我计划允许用户添加反应或键入命令来分配角色。如何在用户不需要管理角色权限的情况下分配角色?
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def hello_world(ctx):
await ctx.send("Hello world!")
client.run(token)
谢谢。
from discord.ext import commands
client = commands.Bot(command_prefix='m.')
token = 'a token goes here'
@client.command()
async def player(ctx):
role = discord.utils.get(ctx.guild.roles, name = "player")
if role is not None:
await ctx.author.add_roles(role)
client.run(token)
您也需要在服务器中具有player
角色。用户发送m. player
作为示例,机器人程序为他提供该角色。