Name
Name

Reputation: 21

How to get a list of all users who reacted in discord.py rewrite

I have searched for an answer to this question, but the only answer I had found was from around a year ago. This is what I have:

@client.command()
async def arena(ctx):
  rembed = discord.Embed(
    title = 'React to join an arena event',
    color = discord.Color.red()
  )
  knife = '🔪'
  message = await ctx.send(embed=rembed)
  await message.add_reaction(knife)
  await asyncio.sleep(3)
  for reaction in message.reactions:
    for user in reaction.users():
      await ctx.send(f"users: {user.name}")

Upvotes: 1

Views: 1053

Answers (1)

Bagle
Bagle

Reputation: 2346

In the discord.py docs, they recommend doing something like this:

users = await reaction.users().flatten()
# users is now a list of User...
winner = random.choice(users)
await channel.send('{} has won the raffle.'.format(winner))

Therefore, in your case, this is what you may want to do.

@client.command()
async def react_test(ctx):
    rembed = discord.Embed(
        title = 'React to join an arena event',
        color = discord.Color.red()
    )
    knife = '🔪'
    message = await ctx.send(embed=rembed)
    await message.add_reaction(knife)
    await asyncio.sleep(3)
    getmsg = await ctx.channel.fetch_message(message.id)
    users = await getmsg.reactions[0].users().flatten()
    for user in users:
        await ctx.send(user.name)

Result of above code:

Who uses only reaction.users().flatten() anyway


Refrences:

Upvotes: 1

Related Questions