如何仅允许管理员执行命令
发布于 2021-01-29 17:57:30
我正在写以下命令
@bot.command(pass_context=True)
async def admins_only_command(ctx, *, args):
'''do stuff
我怎样才能将此命令限制为仅管理员?我试着看,ctx.author.roles.role
它说@everyone
。我如何检查给定的用户是否是admin
?
关注者
0
被浏览
50
1 个回答
-
有两种方法:通过使用的角色白名单
has_any_role
@bot.command(pass_context=True) @commands.has_any_role("Big Cheese", "Medium Cheese") async def admins_only_command(ctx, *, args): '''do stuff'''
或经许可使用
has_permissions
@bot.command(pass_context=True) @commands.has_permissions(administrator=True) async def admins_only_command(ctx, *, args): '''do stuff'''
这两个装饰器都是Checks,
CommandError
如果它们失败,将引发您的一些子类供您选择处理。