繁体   English   中英

我怎样才能使它只有具有特定角色的成员才能执行命令?

[英]How can I make it so only members with a specific role can execute a command?

我的问题可能看起来很常见,但这次有一个转折点。 我需要它来要求一个角色和一个特定角色,而不仅仅是少数几个角色之一。 这是我尝试过但不起作用的代码

@bot.command()
@commands.has_any_role("Buffalo Bills")
@commands.has_any_role("Franchise Owner", "General Manager", "Head Coach", "Assistant Coach")

然后从那里,我命令的 rest。

所以这是你可以做到的一种方法。 使用@commands.has_role()@commands.has_any_role ,您可以确保用户具有一个特定角色以及给定的角色之一。

@client.command()
@commands.has_role('Must Have Role')
@commands.has_any_role('Role One', 'Role Two')
async def role_test(ctx):
    await ctx.send("Hey this worked") 
# This would only send if the user has 'Must Have Role' and either 'Role One' or 'Role Two'

工作图像

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM