由于某种原因,它不允许我在某些具有特定角色“ DJ”的用户访问命令的情况下使用该命令。我已经尝试了一切,但仍然无法正常工作。
@commands.command(pass_context=True, no_pm=True)
async def leave(self, ctx):
if ctx.message.author.roles == 'DJ':
try:
server = ctx.message.server
voice_client = self.client.voice_client_in(server)
await voice_client.disconnect()
except Exception as error:
await self.client.say('{}'.format(error))
else:
await self.client.say('You require the role `DJ` to use this command.')
答案 0 :(得分:0)
author.roles
返回一个Role
对象的列表,因此您必须遍历该列表并找到一个名称为“ DJ”的对象
您可以这样做
if "DJ" in [role.name.upper() for role in ctx.message.author.roles]: