[英]Discord.py: Check if user has role ID from list not working
I'm currently making a reaction role configuration for my Discord.py bot, and I came across an issue trying to blacklist users from picking up roles.我目前正在为我的 Discord.py 机器人进行反应角色配置,但我遇到了一个问题,试图将用户列入黑名单以获取角色。 Here is my code:
这是我的代码:
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
However when I give myself a blacklisted role, it doesn't cancel or dm me, it just continues the process, as if it thinks I don't have the role.然而,当我给自己一个列入黑名单的角色时,它并没有取消或通知我,它只是继续这个过程,就好像它认为我没有这个角色一样。 No errors are given, and I don't know why this is happening.
没有给出错误,我不知道为什么会这样。
Note that everyone id
attribute in discord.py is a base 10 integer, and not a string.请注意,discord.py 中的所有人
id
属性是基数 10 integer,而不是字符串。 Either convert your database results to integers, or the ids to strings:将您的数据库结果转换为整数,或将 ids 转换为字符串:
role_ids = list(map(str, [r.id for r in member.roles]))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.