如何将管理菜单限制为管理员、模组和所有者 (PyCharm 2020.3.3 Python 3.9.1

How to limit Administration menu to Admins, Mods and Owners (PyCharm 2020.3.3 Python 3.9.1

很久以前我创建了一个 Administration cog,但我并没有为管理员限制它。我试图为管理员限制它,但我只能将 cog 限制为一个角色。我如何才能让 cog 仅限于拥有管理员权限的人?

当前代码:

    async def cog_check(self, ctx):
        admin = get(ctx.guild.roles, name="Admin")
        return admin in ctx.author.roles

您可以使用discord.ext.commands.has_permissions() if you need that the person executing the command has a certain permission, otherwise you an also use permissions_for() that return a Permissions object and use the permission administrator

看起来像这样

async def cog_check(self, ctx):
    return ctx.channel.permissions_for(ctx.author).administrator

当且仅当成员具有管理员权限(在他的角色之一中或者如果他在频道中指定了权限)时,此协程将 return 为真