Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

133
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda