Python 如何在discord.py上为特定角色生成命令

Python 如何在discord.py上为特定角色生成命令,python,command,discord.py,roles,Python,Command,Discord.py,Roles,我想检查邮件作者是否具有使用此命令的管理员角色 在我的情况下,它总是给我假,我知道代码是不对的 @client.command(pass_content=True) async def new(ctx, member:discord.Member, nick): role = author.get_role(name="Admin") if role in author.roles: await member.

我想检查邮件作者是否具有使用此命令的管理员角色 在我的情况下,它总是给我假,我知道代码是不对的

 @client.command(pass_content=True)
    async def new(ctx, member:discord.Member, nick):
        role = author.get_role(name="Admin")
        if role in author.roles:
            await member.edit(nick=nick)
            await ctx.send(f"Nickname changed")

您可以在
@client.command中使用
@commands.has_role(“rolename”)

像这样

@client.command(pass_content=True)
@commands.has_role("mod")
async def name(parameters):
   #your code

您可以在
@client.command中使用
@commands.has_role(“rolename”)

像这样

@client.command(pass_content=True)
@commands.has_role("mod")
async def name(parameters):
   #your code

您可以使用
@命令。具有\u角色(角色ID或名称)

对于角色ID:

@bot.command()
@commands.has_角色(123123)
异步def测试(ctx):
等待ctx.send('它工作!')
对于角色名称:

@bot.command()
@commands.has\u role(“role\u name”)
异步def测试(ctx):
等待ctx.send('它工作!')

我强烈建议使用角色id,因为角色名称不唯一。

您可以使用
@命令。has_role(角色id或名称)

对于角色ID:

@bot.command()
@commands.has_角色(123123)
异步def测试(ctx):
等待ctx.send('它工作!')
对于角色名称:

@bot.command()
@commands.has\u role(“role\u name”)
异步def测试(ctx):
等待ctx.send('它工作!')
我强烈建议使用角色id,因为角色名称不是唯一的