Haley
Haley

Reputation: 47

discord.py Pick random user from message reaction

I would like to know how to select a random user from a specific message ID response.

I would like to know how to use the command .voto <id> <Number of people> to randomly select users.

I’m Korean and I used a translator

Upvotes: 0

Views: 460

Answers (1)

Axisnix
Axisnix

Reputation: 2907

You must use Message.reactions and fetch_message

async def voto(ctx, id, num_people):
    msg = ctx.fetch_message(id)
    winners = []
    total_users = []
    reactions = msg.reactions
    for reaction in reactions:
        users = await reaction.users().flatten()
        for user in users:
            total_users.append(user)
    for I in range(num_people):
        winners.append(I.name)  # Add the name to winners
    winners_msg = '\n'.join(winners)
    await ctx.send(f"{winners_msg}\nHas won")

Upvotes: 1

Related Questions