我想创建一个discord bot,为Python中的成员提供角色 .
我试过这个:
@async def on_message(message): if message.content == "give me admin" role = discord.utils.get(server.roles, name="Admin") await client.add_roles(message.author.id, role)
import discord from discord.utils import get client = discord.Client() @client.event async def on_message(message): if message.author == client.user: return if message.content == 'give me admin': role = get(message.server.roles, name='Admin') await client.add_roles(message.author, role)
我认为这应该有效 . discord.py的文档是here .
您还可以使用 discord.ext.commands 扩展名:
discord.ext.commands
from discord.ext.commands import Bot import discord bot = Bot(command_prefix='!') @bot.command(pass_context=True) async def addrole(ctx, role: discord.Role, member: discord.Member=None): member = member or ctx.message.author await client.add_roles(member, role) bot.run("token")
1 回答
我认为这应该有效 . discord.py的文档是here .
您还可以使用
discord.ext.commands
扩展名: