仅管理员命令 [英] Admins only command

查看:22
本文介绍了仅管理员命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只有选定的用户 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))

您可以在 commands 扩展 在文档中

这篇关于仅管理员命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆