简体   繁体   中英

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. 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. Either convert your database results to integers, or the ids to strings:

role_ids = list(map(str, [r.id for r in member.roles]))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM