Search code examples
javascriptnode.jsdiscorddiscord.jsbots

Discord.js react to all messages in channel


I’m trying to create a bot that should react with 👍 and 👎 to all messages sent in a specific channel.

I’ve watched tutorials on youtube and google, but nothing has worked so I must be missing something.

I’m currently on my phone - so I am unable to share my code as well as images atm. Though I can tell you that I have all handlers and commands in separate files and folders.


Solution

  • This should serve your purposes:

    Discord v12

    client.on('message', async message => {
        if (message.channel.id === 'channelId') {
            if (message.member.user.bot) return
            message.react('👍').then(() => {
                message.react('👎')
            })
        }
    })
    

    Discord v13

    client.on('messageCreate', async message => {
        if (message.channel.id === 'channelId') {
            if (message.member.user.bot) return
            message.react('👍').then(() => {
                message.react('👎')
            })
        }
    })
    

    Keep in mind that, aside from bot messages, it will react to all messages with those emojis. Now if you are trying to create a suggestions channel, there are better and better looking ways to do that.

    But I also agree with @Jan in your comments, please post meaningful questions with homework shown next time.