首页 > 解决方案 > 如何检查用户是否在角色列表中具有特定角色?(discord.py)

问题描述

当尝试运行此代码时,没有任何反应。顺便说一句,没有错误。我得到了一个角色列表来让它工作,但它没有。

rolelist = [822428355554312212,
            822728446059741218,
            823814683973779488]

check = ''

if rolelist in user.roles:
    check += 'Bot Developer'

标签: pythondiscord.py

解决方案


还有另一种方式。你可以使用内置的。

链接到文档:https ://discordpy.readthedocs.io/en/latest/ext/commands/api.html#discord.ext.commands.has_any_role

文档中的示例:

@bot.command()
@commands.has_any_role('Library Devs', 'Moderators', 492212595072434186)
async def cool(ctx):
    await ctx.send('You are cool indeed')

推荐阅读