Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

130
Visualizações
Discord.js multiple reaction collector

How do I make this code work with multiple reactions? I would like the embed to have multiple reactions, and based on the selected reaction, it would give a different response Here's the code:

module.exports = {
    name: 'test',
    description: "ping command",
    async execute(message, args, Discord){
        
        var newEmbed = new Discord.MessageEmbed()
        .setColor('#A5775C')
        .setTitle('Reactions')
        .setDescription('*React to this!')
        
const MAX_REACTIONS = 1;
        
      const sentMessage = await message.channel.send({embeds: [newEmbed]});

      await sentMessage.react('🐸');

      const filter = (reaction, user) => reaction.emoji.name === '🐸' && !user.bot;

      const collector = sentMessage.createReactionCollector({
        filter,
        max: MAX_REACTIONS,
      });

      collector.on('end', (collected, reason) => {

        if (reason === 'limit')
          return message.channel.send(`You reacted with 🐸!`);
      });
    }
  }```
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First you need to add all the needed reactions to the message:

await sentMessage.react('emoji');
await sentMessage.react('emoji_2');
await sentMessage.react('emoji_3');
// ... //

Now, you need to edit the filter(reaction, user) function. reaction.emoji.name === '🐸' means that the collector will only respond to one emoji - 🐸. If you want the collector to respond to different emojis, you can just delete this expression. In this case, the collector will respond to any emoji. But, you can also make the collector respond to a specific list of emoji:

const filter = (reaction, user) => ["emoji1", "emoji2", "emoji3" /* ... */].includes(reaction.emoji.name) && !user.bot
// the collector will now respond to all the emoji in the array

And finally, to display the user-selected emoji instead of 🐸, replace the string in message.channel.send():

message.channel.send(`You reacted with ${collected.first().emoji.name}!`);

Also, I can offer you 2 more optional things to improve the code:

  1. Since the code is written specifically to collect one reaction, the MAX_REACTIONS constant probably won't change. So you can get rid of it and use 1 when creating the collector.
  2. Because you do not pass the time property when you create the collector, the collector will last indefinitely if the author of the command does not choose a reaction. Therefore, you can pass the idle property and specify the time in milliseconds when creating the collector. After the specified number of milliseconds of inactivity, the collector will stop. For example:
const collector = sentMessage.createReactionCollector({
    filter,
    max: 1,
    idle: 10000 // the collector will stop after 10 seconds of inactivity
});

If the collector stops due to inactivity, reason will be "idle", inside collector.on("end", ...):

collector.on('end', (collected, reason) => {
    if (reason === "limit") {
        return message.channel.send(`You reacted with ${collected.first().emoji.name}!`);
    } else if (reason === "idle") {
        // ... //
    }
});
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda