How To Make A Discord Bot Asynchronously Wait For Reactions On Multiple Messages?
tl;dr How can my bot to asynchronously wait for reactions on multiple messages? I'm adding a rock-paper-scissors (rps) command to my Discord bot. Users can invoke the command can
Solution 1:
You should be able to use asyncio.gather
to schedule multiple coroutines to execute concurrently. Awaiting gather
waits for all of them to finish and returns their results as a list.
from asyncio import gather
@bot.command()
async def rps(ctx, opponent: discord.User = None):
"""
Play rock-paper-scissors!
"""
if opponent is None:
opponent = bot.user
author_helper = rps_dm_helper(ctx.author, opponent) # Note no "await"
opponent_helper = rps_dm_helper(opponent, ctx.author)
author_emoji, opponent_emoji = await gather(author_helper, opponent_helper)
...
Post a Comment for "How To Make A Discord Bot Asynchronously Wait For Reactions On Multiple Messages?"