【问题标题】:if there a way to check does the author have perms but if i am (bot owner) is the author it works regardless如果有办法检查作者是否有权限,但如果我是(机器人所有者)是作者,它无论如何都可以工作
【发布时间】:2021-07-23 15:20:55
【问题描述】:

我希望我的代码检查消息作者是否有权删除消息,但同时如果我(机器人所有者)是作者,我希望它能够工作而不管权限如何

@client.command(aliases = ['clear'])
@commands.has_permissions(manage_messages = True)
async def purge(ctx , number : int = None):
    if number is None:
        await ctx.send("Please enter number of messages to delete with the command")
        await ctx.message.delete()
    else:
        await ctx.channel.purge(limit = number + 1)

这是我的代码

【问题讨论】:

    标签: python python-3.x discord discord.py


    【解决方案1】:

    使用 commands.check_any 装饰器

    @client.command(aliases=["clear"])
    @commands.check_any(commands.has_permissions(manage_messages=True), commands.is_owner())
    async def purge ...
    

    参考:

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 2020-11-19
      • 2018-09-14
      • 1970-01-01
      • 2019-11-23
      • 1970-01-01
      相关资源
      最近更新 更多