F
F
ferrson2020-08-19 14:31:46
Python
ferrson, 2020-08-19 14:31:46

How to find out all users who have reacted to a selected message in discord.py?

Hello! I create a function for the bot that collects participants and forwards them to the server.

(The code)

@bot.command()
async def start(ctx):
    channel = ctx.message.channel
    mess = await channel.send('Набор в игру')
    ID = mess.id
    r = bot.Reaction
    await asyncio.sleep(10)
    mess = await channel.fetch_message(ID)


I looked at the documentation, but when I try to get all users like this:
mess.Reaction.users() - it shows that Reaction is not a Message attribute ..
How can I find out?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Nevzorov, 2020-08-20
@Proffs

The attribute you want is called Message.reactions. discord.Reaction- the type of objects returned in reactions.
discord.Message.reactions

@bot.command()
async def start(ctx):
    mess = await channel.send('Набор в игру')
    await asyncio.sleep(10)
    mess = await ctx.channel.fetch_message(mess.id)
    if yes_react := discord.utils.get(mess.reactions, emoji=ctx.guild.get_emoji(471483388532742130)):
        async for user in yes_react.users:
            print(str(user))  # выведет всех пользователей поставивших реакцию в консоль

U
UberPool, 2020-08-19
@UberPool

Perhaps the corgi option does not suit you, but still:

@commands.Cog.listener()
    async def on_raw_reaction_add(self, payload):
        members_list = []
        if payload.message_id == 745708593348739214: 
            if payload.emoji.name == '':   #эмоция которую нужно поставить
                guild = self.bot.get_guild(payload.guild_id)
                member = guild.get_member(payload.user_id)
                members_list.append(f'{member}')
                #и делаешь что-то

As you were told earlier, write down the id of the participants somewhere and do whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question