如何在不使用装饰器的情况下使用Python在Discord机器人中检查管理员角色或特定权限?
给出以下示例:
@client.command()
# @commands.has_permissions(manage_messages=True) # Don't want this here
async def test(c):
'''A command for testing stuff'''
if c.author.Permissions.administrator: # this is deprecated form
await author.send("Hello Admin person")
else:
await author.send("You are not an admin, so you get different stuff")
return
我了解如何在装饰器上使用.has_permissions方法进行检查(如上例所示)。我不相信这可以像上面所说的那样拆分命令。我已经看到了使用装饰器和错误捕获的示例,但是如果我没记错的话,这是一种草率的处理方式,因为任何错误都会触发错误处理程序并在 else 阻止。
我发现了显示c.author.Permissions.administrator
语法的较旧的示例,但这不再有效,但是我无法在文档中找到此过程的新格式。