Discord bot reading reactions Discord bot reading reactions python-3.x python-3.x

Discord bot reading reactions


As an aside, given you're starting this project, and are already using the rewrite documentation, make sure you're using the rewrite version. There are some questions on here about how to make sure, and how to get it if you're not, but it's better documented and easier to use. My answers below assume you are using

  1. Message.reactions is a list of Reactions. You could get a mapping of reactions to their counts with

    {react.emoji: react.count for react in message.reactions}
  2. You could react to the message immediately after posting it:

    @bot.command()async def poll(ctx, *, text):    message = await ctx.send(text)    for emoji in ('👍', '👎'):        await message.add_reaction(emoji)
  3. You can use Message.pin: await message.pin()

I'm not sure what you mean by "user tags". Do you mean roles?

I would write your command as

@bot.command()async def create_poll(ctx, text, *emojis: discord.Emoji):    msg = await ctx.send(text)    for emoji in emojis:        await msg.add_reaction(emoji)

Note that this will only work for custom emoji, the ones you have added to your own server (This is because discord.py treats unicode emoji and custom emoji differently.) This would accept commands like

!create_poll "Vote in the Primary!" :obamaemoji: :hillaryemoji:

assuming those two emoji were on the server you send the command in.

With the new commands.Greedy converter, I would rewrite the above command like so:

@bot.command()async def create_poll(ctx, emojis: Greedy[Emoji], *, text):    msg = await ctx.send(text)    for emoji in emojis:        await msg.add_reaction(emoji)

So invocation would be a little more natural, without the quotes:

!create_poll :obamaemoji: :hillaryemoji: Vote in the Primary!


I have just seen what you are stuck and I was stuck at this too. The solution is that reactions are not actually things like ":one:" it is actual emojis, there are different ways to fix this, the simplest being adding them to the dictionary yourself. Or you can use python3 -m pip install discordhelp and use the functions for it listed here.