如何在不协调.py中授予用户角色而不授予管理角色权限



我计划允许用户添加反应或键入命令来分配角色。如何在用户不需要管理角色权限的情况下分配角色?

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作为示例,机器人程序为他提供该角色。

最新更新