When running a Discord bot using discord.py, if a user's roles are edited, the information can't be see by the bot. For example:
1: User A (not in role R) uses the "join" command. Bot adds user to R.
User A (now in role R) uses the "leave" command. Bot thinks that the user isn't in R and complains.
2: User A (in role R) uses the "leave" command. Bot removes user from R
User A (not in role R) uses the "join" command. Bot thinks the user is in R already and complains.
If I use a debugger and inspect the given user, it appears that the role never gets added/removed. The role change does appear within Discord itself though. Restarting the bot allows one update again before it breaks, so it makes me think that something isn't updating when the user's roles change.
The code is pretty straightforward too:
async def giveRole(user, wantedRole, message):
role = getRoleToAdd(wantedRole) # some logic to get the role to leave/join, verified to work
if role in user.roles:
await message.channel.send("You've already joined that role")
else:
await user.add_roles(role)
The "leave" logic is just flipped, using user.remove_roles(role) instead.
intents
? - hardestchat