【问题标题】:discord.py: Can i make it so i, the bot owner, can use any command in any server regardless of whether i have the required perms or not?discord.py:我能做到吗,所以我,机器人所有者,可以在任何服务器上使用任何命令,无论我是否具有所需的权限?
【发布时间】:2021-04-28 14:48:31
【问题描述】:

我想让拥有manage_messages 权限的人可以使用该命令,加上我,机器人的所有者,即使我没有manage_messages 权限也可以使用该命令。这是我到目前为止的代码:

@commands.command()
  @commands.has_permissions(manage_messages = True)
  async def spam(self, ctx, msg, delay: int):
    global on
    on = True
    while on:
      await ctx.send(msg)
      await asyncio.sleep(int(delay))
  @spam.error
  async def spam_error(self, ctx, error):
    if isinstance(error, commands.MissingRequiredArgument):
        await ctx.send(f"Missing argument(s). Proper usage: `{prefix}spam <message to spam> <delay in seconds>`")
    if isinstance(error, commands.MissingPermissions):
        await ctx.send("Missing permission(s): Manage_Messages")
    if isinstance(error, commands.BadArgument):
      await ctx.send("The delay must be an integer")
  

【问题讨论】:

    标签: python discord discord.py


    【解决方案1】:

    是的,有可能。

    
    @commands.check_any(commands.is_owner(), commands.has_permissions(manage_messages=True)
    @commands.command()
    # command  here
    

    参考资料:

    • check_any 如果任何一项检查返回 true,则返回 true
    • 如果作者是机器人的所有者,is_owner 返回 true。

    注意: 不确定,但是,如果您使用机器人绕过 mod 命令并自己使用它,则可能违反 ToS。

    【讨论】:

      猜你喜欢
      • 2021-07-23
      • 1970-01-01
      • 2021-09-14
      • 2020-06-26
      • 2020-07-14
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 2021-02-02
      相关资源
      最近更新 更多