我如何才能使其只有具有特定角色的成员才能执行命令?

2024-05-23 19:12:35 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

然后从那里开始,我其余的命令


Tags: 代码角色botanycommandcommandsrolegeneral
1条回答
网友
1楼 · 发布于 2024-05-23 19:12:35

因此,这里有一种方法可以做到这一点。使用^{}^{},您可以确保用户拥有一个特定的角色以及给定的角色之一

@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'

Working Image

相关问题 更多 >