discord.py 从消息反应中选择随机用户

时间:2021-01-10 14:57:49

标签: discord.py

我想知道如何从特定的消息 ID 响应中选择随机用户。

我想知道如何使用命令 .voto <id> <Number of people> 随机选择用户。

我是韩国人,我用过翻译

1 个答案:

答案 0 :(得分:1)

您必须使用 Message.reactionsfetch_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")