【发布时间】:2021-06-20 20:42:53
【问题描述】:
我有一个命令可以删除用户输入的指定数量的消息。我希望只有我和具有管理员角色的人才能访问此命令。我以前用 if 语句实现过这个,它工作得很好。但是,现在我正在尝试使用命令装饰器来做同样的事情,它只允许管理员使用命令 - 而不是我。这是我正在使用的代码:
@bot.command(description="clears entered amount of messages")
@commands.is_owner() # checks if user is owner
@commands.has_permissions(administrator=True) # checks if user is admin
async def delete(ctx, amount : int):
await ctx.channel.purge(limit = amount + 1)
我认为@commands.has_permissions(administrator=True) 阻止我使用该命令,因为我不是其中一台服务器的管理员。我试过切换他们的订单,is_owner() 支票低于has_permissions() 支票;尽管如此,它仍然不允许我使用该命令。如何使用装饰器克服这个问题?
【问题讨论】:
标签: python discord discord.py