【发布时间】:2021-10-01 22:36:19
【问题描述】:
我有一个不和谐的机器人,它通过以下命令检查用户角色:
@commands.has_role("Lab Demonstrator")
但是,在多台服务器上,每台服务器的角色设置略有不同,我想检查他们是否拥有“实验室演示者”或“员工”或“教师”权限
我试过了
@commands.has_role("Lab Demonstrator" OR "Staff")
并没有成功。
【问题讨论】:
标签: discord.py
我有一个不和谐的机器人,它通过以下命令检查用户角色:
@commands.has_role("Lab Demonstrator")
但是,在多台服务器上,每台服务器的角色设置略有不同,我想检查他们是否拥有“实验室演示者”或“员工”或“教师”权限
我试过了
@commands.has_role("Lab Demonstrator" OR "Staff")
并没有成功。
【问题讨论】:
标签: discord.py
使用commands.has_any_role 装饰器:
@commands.has_any_role("Lab Demonstrator", "Staff", "Teacher")
async def ...
【讨论】:
如果您仅检查角色以确保成员具有权限,那么通常这不是一个好的做法。您可以改为使用
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。即使角色名称或相关服务器发生更改,这也可确保权限的一致性。
【讨论】: