python - Discord.py:检查用户是否具有列表中的角色 ID 不起作用
问题描述
我目前正在为我的 Discord.py 机器人进行反应角色配置,我遇到了一个问题,试图将用户列入黑名单以获取角色。这是我的代码:
cursor.execute(f"SELECT blacklists FROM reactionroles WHERE message_id = {payload.message_id} AND emojis = '{reaction}'")
blacklist_result = cursor.fetchone()
member = payload.member
rolesUserHas = member.roles
rolesIDuserHas = []
for role in rolesUserHas:
rolesIDuserHas.append(role.id)
print(rolesIDuserHas)
if any(item in blacklist_result for item in rolesIDuserHas):
await member.send(f'{x_mark} You are blacklisted from picking up roles from that message.')
return
else:
pass
然而,当我给自己一个列入黑名单的角色时,它并没有取消或通知我,它只是继续这个过程,就好像它认为我没有这个角色一样。没有给出错误,我不知道为什么会这样。
解决方案
Note that everyone id
attribute in discord.py is a base 10 integer, and not a string. Either convert your database results to integers, or the ids to strings:
role_ids = list(map(str, [r.id for r in member.roles]))
推荐阅读
- python - 从类中的函数更改 tk.label 文本
- draftjs - Draft-JS - 数据更改时实体组件不会重新呈现
- instagram-api - Instagram 基本显示 api 替代图片尺寸
- javascript - 猫头鹰轮播导航在 html 中出现在同一行
- angular - 离子显示值已选中复选框
- php - 有没有什么有效的方法可以在 mysql 中获得“similar_text()”的替代解决方案?
- android - 如何使来自我的 Android 应用程序的所有 HTTP 请求都接受给定的证书颁发机构?
- java - 是否有使用 HttpUrlConnection 的 AsyncTask 的替代方案
- linux - 启用 Systemd 的服务不再在启动时启动
- perl - 如何使用perl获取一个字符的位置及其另一个出现并在文件中每一行的两个位置之间打印