仅限管理员命令 [英] Admins only command
本文介绍了仅限管理员命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
只有选定的用户ID才有权使用此命令。像下面这样,只有在此列表中添加的用户ID才应该获得使用该命令的权限。
Only selected user id's should have permission to use this command. like below only user ids added in this list should get permission to use that command.
def is_any_user(ids):
async def predicate(ctx):
return ctx.author.id in ids
return commands.check(predicate)
LIST_OF_ADMINS = [3557657657647676, 36567565756766767, 343657687786435432]
@bot.command(pass_context=True)
@is_any_user(LIST_OF_ADMINS)
async def hello(ctx):
await bot.say("Hello {}".format(ctx.message.author.mention))
推荐答案
您可以编写自己的支票来装饰命令
You can write your own check that can decorate the command
def is_any_user(ids):
def predicate(ctx):
return ctx.message.author.id in ids
return commands.check(predicate)
LIST_OF_ADMINS = ['3557657657647676', '36567565756766767', '343657687786435432']
@bot.command(pass_context=True)
@is_any_user(LIST_OF_ADMINS)
async def hello(ctx):
await bot.say("Hello {}".format(ctx.message.author.mention))
这篇关于仅限管理员命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文