Blueerd
Blueerd

Reputation: 21

I can't get my bot to recognize the reaction and respond to it (Discord.js)

const Discord = require ('discord.js')

module.exports.run = async (client, message, reaction, user) => {
        
        message.channel.send("Press **F** to pay respect!!").then(msg => {msg.react("<:pressf:861646469180948530>")})
        
        const filter = (reaction, user) => {
                return reaction.emoji.name === ' === "<:pressf:861646469180948530>' && user.id === message.author.id;
                
        };
        
        
        const collector = message.createReactionCollector( filter);
        
        
        collector.on('collect', (reaction, user) => {
                if (message.emoji.name === "<:pressf:861646469180948530>"){
                        message.channel.send("You pay respect!!")
                }
        })
        
};

Upvotes: 2

Views: 43

Answers (1)

Zsolt Meszaros
Zsolt Meszaros

Reputation: 23161

The problem is you're setting up the reaction collector on the original message. Try to wait for the sent one, and accept reactions on that:

module.exports.run = async (client, message, reaction, user) => {
  const sentMessage = await message.channel.send('Press **F** to pay respect!!');

  sentMessage.react('<:pressf:861646469180948530>');

  const filter = (reaction, user) =>
    // there was an extra  === " here
    reaction.emoji.name === '<:pressf:861646469180948530>' &&
    user.id === message.author.id;

  const collector = sentMessage.createReactionCollector(filter);

  collector.on('collect', (reaction, user) => {
    if (reaction.emoji.name === '<:pressf:861646469180948530>') {
      message.channel.send('You pay respect!!');
    }
  });
};

Upvotes: 2

Related Questions