python - 如何检查用户是否在角色列表中具有特定角色?(discord.py)
问题描述
当尝试运行此代码时,没有任何反应。顺便说一句,没有错误。我得到了一个角色列表来让它工作,但它没有。
rolelist = [822428355554312212,
822728446059741218,
823814683973779488]
check = ''
if rolelist in user.roles:
check += 'Bot Developer'
解决方案
还有另一种方式。你可以使用内置的。
链接到文档: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')
推荐阅读
- angular - src/app/app.component.ts(20,27) 中的错误:错误 TS2345:'string | 类型的参数 ArrayBuffer' 不可分配给“字符串”类型的参数
- javascript - 使用简化方法在两个给定日期之间生成一系列日期
- hive - 在 hive 中向外部表添加分区需要很多时间
- pandas - 通过屏蔽特定行之间的子集 df
- java - 如何使用 Spring Boot 向应用程序中的所有现有 API 添加新的请求标头
- c - 努力使最长公共子序列代码并行(C)
- datatables-1.10 - 如果列存在,如何添加“columnDefs”?
- r - is.na() 替换所有值而不是 na 值
- firebase - 基于多个相同列的Angularfire查询
- flutter - 禁用 androidX - 颤动