How to allow only admins to execute a command

前端 未结 1 1010
有刺的猬
有刺的猬 2020-12-07 05:09

i am writing following command

@bot.command(pass_context=True)
async def admins_only_command(ctx, *, args):
    \'\'\'do stuff

how can i re

相关标签:
1条回答
  • 2020-12-07 05:58

    There are two ways: by a whitelist of roles using 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'''
    

    or by permission using has_permissions

    @bot.command(pass_context=True)
    @commands.has_permissions(administrator=True)
    async def admins_only_command(ctx, *, args):
        '''do stuff'''
    

    Both of these decorators are Checks, and will raise some subclass of CommandError for you to optionally handle if they fail.

    0 讨论(0)
提交回复
热议问题