如何让我的机器人检查作者是否有管理员并在没有时发送消息?

How can I make my bot check if the author has administrator and send a message if they don't?

我做了一个命令,我希望只有管理员可以访问。如果用户有管理员权限,则运行特定代码。如果没有,我希望机器人发送一条消息,例如“抱歉,您不能使用那个”。有办法吗?

    @commands.command()
    @commands.has_permissions(administrator=True)
    async def command(self, ctx):
          #code here

将使命令 command 仅限管理员。 至于警告用户尝试 运行 他们没有权限的命令,您可以使用错误处理程序/命令特定的错误处理程序。 如

    @commands.Cog.listener()
    async def on_command_error(self, ctx, error):
        if isinstance(error, commands.errors.MissingPermissions):
            msg.title = "Missing Permission ⛔"
            msg.description = error.args[0]
            return await ctx.send(embed=msg)

对于特定于 cog 的错误,请使用 commandname.error() 并捕获如上所示的错误。