【问题标题】:Discord.py using multiple permission check decorators on command methodsDiscord.py 在命令方法上使用多个权限检查装饰器
【发布时间】:2021-07-15 01:37:29
【问题描述】:

我正在发出命令test。 我只希望用户能够使用该命令;

  • 是机器人所有者
  • 拥有manage_channels 权限

目前我正在做

@client.command()
@commands.has_permissions(manage_channels=True)
@commands.check(commands.is_owner())
async def test(ctx):
  await ctx.reply("Success!")

但是一旦我 - 机器人所有者 - 尝试在没有 manage_channels 许可的情况下使用它,它就不起作用。我假设它一看到我没有权限就被@commands.has_permissions() 阻止了?

我知道我总是可以只检查方法本身,但我知道使用装饰器是更好的方法?

提前致谢。

【问题讨论】:

    标签: python asynchronous discord discord.py python-decorators


    【解决方案1】:

    你可以使用commands.check_any装饰器

    @client.command()
    @commands.check_any(commands.is_owner(), commands.has_permissions(manage_channels=True))
    async def ...
    

    参考:

    【讨论】:

      猜你喜欢
      • 2019-03-06
      • 2013-02-09
      • 2019-11-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多