【问题标题】:Allowing users with a certain role access to a command允许具有特定角色的用户访问命令
【发布时间】:2018-10-14 21:20:54
【问题描述】:

由于某种原因,它不允许我在某些具有特定角色“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.')

【问题讨论】:

标签: python-3.x discord discord.py


【解决方案1】:

author.roles 返回Role 对象的列表,因此您必须遍历该列表并找到名称为“DJ”的对象

你可以这样做

if "DJ" in [role.name.upper() for role in ctx.message.author.roles]:

【讨论】:

    猜你喜欢
    • 2020-09-07
    • 2012-02-24
    • 2021-12-25
    • 2017-12-21
    • 1970-01-01
    • 2018-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多