【问题标题】:how to make command for specific role on discord.py如何在 discord.py 上为特定角色创建命令
【发布时间】:2021-08-05 17:05:47
【问题描述】:
我想检查消息作者是否具有使用此命令的管理员角色
就我而言,它总是给我 False,我知道代码不正确
@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")
【问题讨论】:
标签:
python
command
discord.py
roles
【解决方案1】:
您可以使用@commands.has_role(role ID or name)
对于角色 ID:
@bot.command()
@commands.has_role(123123)
async def test(ctx):
await ctx.send('It works!')
对于角色名称:
@bot.command()
@commands.has_role("role_name")
async def test(ctx):
await ctx.send('It works!')
我强烈建议使用角色 ID,因为角色名称不是唯一的。
【解决方案2】:
你可以在你的@client.command中使用@commands.has_role("rolename")
喜欢这个
@client.command(pass_content=True)
@commands.has_role("mod")
async def name(parameters):
#your code