Search code examples
pythondiscorddiscord.pyembed

How to add reaction to message sent from bot


My bot sends a embed into a specific channel, after that he should also add 2 reactions to his embed he sent. But i'm kinda stuck at that and searching through website wasn't successful.

if '!suggestion' in message.content:
        if "salus insured" in [y.name.lower() for y in message.author.roles]:
            channel = client.get_channel(938973763414921316)
            embedVar = discord.Embed(title="User suggestion, vote below!", color=0x03b2f8)
            embedVar.add_field(name="Suggestion", value="```"+substring+"```", inline=False)
            embedVar.add_field(name="Suggested by", value="<@{}>".format(message.author.id))
            embedVar.set_footer(text="Suggestion Poll | @Salus", icon_url="https://i.imgur.com/rwBBzGK.png")
            await channel.send(embed=embedVar)
            await message.delete()

That's the last part of my code.


Solution

  • You should first retain the message object of the message the bot sends with...

    msg = await channel.send("whatever")
    

    You can then do things with that message object msg as you would any other message.

    So in your case:

    msg.add_reaction(emoji)
    

    There are several helpful hints for finding different emoji (e.g. custom emoji) in this question here