我有一个不一致的机器人,它通过以下命令检查用户角色:
@commands.has_role("Lab Demonstrator")
然而,在多台服务器上,每台服务器的角色设置都略有不同,我想检查他们是否具有“实验室演示者”或“工作人员”或“教师”的权限。
我试过@commands.has_role("Lab Demonstrator" OR "Staff")
但并没有成功。
发布于 2021-10-01 11:47:26
使用commands.has_any_role
装饰器:
@commands.has_any_role("Lab Demonstrator", "Staff", "Teacher")
async def ...
发布于 2021-10-01 14:36:20
如果您只检查角色以确保成员具有权限,那么通常这不是一个好的做法。您可以改用
from discord.ext.commands import has_permissions
...
@client.command(name='whatever')
@has_permissions(administrator=True) #or whichever permissions you want here
manage_webhooks
、ban_members
和create_instant_invite
就是几个例子。这确保了权限的一致性,即使角色名称或相关服务器发生更改也是如此。
https://stackoverflow.com/questions/69405369
复制相似问题