2
votes

Is there any to use wait_for in such a way that it will wait for either reaction_add or reaction_remove?

I've seen that there are on_reaction_add and on_reaction_remove functions, but I would like a way to do it without those.

I want something like this:

reaction,user=await bot.wait_for('reaction_add/reaction_remove',check=check)
1

1 Answers

4
votes

Since this looks to be using asyncio facilities, use the built-ins. Just create a task for each, then use asyncio.wait to wait for the first one to fire:

pending_tasks = [bot.wait_for('reaction_add',check=check),
                 bot.wait_for('reaction_remove',check=check)]
done_tasks, pending_tasks = await asyncio.wait(pending_tasks, return_when=asyncio.FIRST_COMPLETED)

When one of the tasks completes, this will return, and the task which was satisfied will appear in the done_tasks set. If you're no longer interested in other tasks once one of them completes, you can go ahead and cancel the others, e.g.:

for task in pending_tasks:
    task.cancel()