Python - Is It Possible To Wait_for One Event Or Another In Discord.py-v1.0?
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,
Solution 1:
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()
Post a Comment for "Python - Is It Possible To Wait_for One Event Or Another In Discord.py-v1.0?"