Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
Colector de reacciones múltiples de Discord.js

¿Cómo hago que este código funcione con múltiples reacciones? Me gustaría que la inserción tuviera múltiples reacciones y, según la reacción seleccionada, daría una respuesta diferente. Aquí está el código:

 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 answers
Answer question

0

Primero debe agregar todas las reacciones necesarias al mensaje:

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

Ahora, necesita editar la función de filter(reaction, user) . reaction.emoji.name === '🐸' significa que el coleccionista solo responderá a un emoji: 🐸. Si desea que el coleccionista responda a diferentes emojis, simplemente puede eliminar esta expresión. En este caso, el coleccionista responderá a cualquier emoji. Pero también puedes hacer que el coleccionista responda a una lista específica de 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

Y finalmente, para mostrar el emoji seleccionado por el usuario en lugar de 🐸, reemplaza la cadena en message.channel.send() :

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

Además, puedo ofrecerte 2 cosas más opcionales para mejorar el código:

  1. Dado que el código está escrito específicamente para recopilar una reacción, la constante MAX_REACTIONS probablemente no cambie. Entonces puede deshacerse de él y usar 1 al crear el colector.
  2. Debido a que no pasa la propiedad de time cuando crea el recopilador, el recopilador durará indefinidamente si el autor del comando no elige una reacción. Por lo tanto, puede pasar la propiedad de idle y especificar el tiempo en milisegundos al crear el recopilador. Después del número especificado de milisegundos de inactividad, el recopilador se detendrá. Por ejemplo:
 const collector = sentMessage.createReactionCollector({ filter, max: 1, idle: 10000 // the collector will stop after 10 seconds of inactivity });

Si el colector se detiene debido a la inactividad, el reason será "idle" , dentro 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!