Search code examples
discordbotsdiscord.pyresponse

Discord.py make discord bot react to message with several emotes


I know how to make a bot react to a message, but I am stuck with my project and I'm just running constantly into troubles. I want to do a command with the syntax -react [message ID] [emote1] [emote2] [emote 3] [emote ...] that reacts to the message belonging to the ID with the emotes I put after the ID.

I know how to make the bot react with the same emotes to always the same message, and tried to make it react to other messages with the code:

@client.command()
async def react(ctx, ID):
    emotes = ['❤️', '🏠']
    msg = message.fetch_message(ID)
    for emote in emotes:
        await ctx.msg.add_reaction(emoji=emote)

but this always puts out NameError: name 'message' is not defined in msg = message.fetch_message(ID), and additionally I have not the slightest idea how to make it work with own chosen emotes.

So, my main problems are:

  1. How can I make the bot react to specific messages? (Solved)
  2. How can I make it using own specified emotes?

Update: First problem solved, I simply needed to add

message_id = ID
    msg = await ctx.fetch_message(message_id)

but I'm still stuck with making it react with user given emotes, not hard-coded ones.


Solution

    1. You didn't define message variable, that's why it's throwing that error.
    2. The ID arg is a string, ids must be integers
    3. ctx doesn't have the attribute msg it's message

    Also to implement the emojis you can simply pass them as a tuple and go through them using a for loop.

    @client.command()
    async def react(ctx, ID: int, *emojis):
        message = ctx.fetch_message(ID)
    
        for emoji in emojis:
            await message.add_reaction(emoji)
            # Or if you want to add the reactions to the message which invoked the command
            await ctx.message.add_reaction(emoji)