Expected output and what my code for it is:
My bot is supposed to send a message, and then check if somebody reacted on that message with :tada:, and if someone did, it is supposed to give that user a particular role, that part works fine, but I also want it to check if the user removed their reaction, if yes, then remove the role.
I put the role remover and role adder into their own async coroutine functions,
# Listening for reactions
await participation_message.add_reaction("????")
reaction_check = lambda reaction, user: str(reaction.emoji) == "????" and reaction.message.id == participation_message.id # In case you might be wondering, participation_message is a discord.Message that I send before this code block
async def remove_participants_loop():
while True:
try:
reaction, user = await self.client.wait_for('reaction_remove', timeout=60, check=reaction_check)
try:
await user.remove_roles(participant_role)
except Exception as e:
console_log("Error in removing participant role from user: {}".format(e), "white", "on_red")
except TimeoutError:
break
async def add_participants_loop(timeout=delete_after*60):
while True:
try:
reaction, user = await self.client.wait_for('reaction_add', timeout=60, check=reaction_check)
try:
await user.add_roles(participant_role)
except Exception as e:
console_log("Error in adding participant role to user: {}".format(e), "white", "on_red")
except TimeoutError:
break
and I put them into their own coroutines, because I need both of them to run asynchronously, and for that I now do
asyncio.create_task(add_participants_loop())
asyncio.create_task(remove_participants_loop())
The problem:
This works for the add_participants_loop() but doesn't work for the remove_participants_loop(), I have tried to debug it using breakpoints, and found that the remove_participants_loop does run properly, but when it waits for "reaction_remove", it doesn't detect it when I remove my reaction, and keeps waiting and eventually raises the asyncio.TimoutError.
I have tried:
- reading the documentation, and the function
wait_for()'s documentation states that, "event (str) – The event name, similar to the event reference, but without the on_ prefix, to wait for.", and the event reference shows that the proper term would indeed be "reaction_remove" and not anything else - Checking for typos
- Making sure that Bot.Intent.reactions == True
- Making sure that I have latest version of discord.py module
- Debugging with breakpoints just as mentioned above.
- Contemplating my sanity that after all this the issue would turn out to be just some dumb typo that i missed.
- Making sure that my bot has all the permissions it needs in its roles in discord
str(reaction.emoji) == "🎉"? - Black Thunder