2024-05-19 00:03:27 发布
网友
我想创建一个不和谐的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")
我认为这应该管用。discord.py的文档是here。
您还可以使用
discord.ext.commands
扩展名:相关问题 更多 >
编程相关推荐