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

180
Views
El retorno de Discord.js v13 en el recopilador de mensajes no deja de recopilar

Intento crear un comando de "Configuración" con message.channel.createMessageCollector() en Discord.js v13. Quiero que el usuario escriba quit para cancelar/abortar el comando. Estoy intentando con este código usando un return dentro del colector que no lo detiene:

 const filter = (m) => { return m.author.id === message.author.id; }; const collector = message.channel.createMessageCollector({ filter, max: 5, time: 1000 * 20, }); collector.on("collect", (collect) => { if (collect.content.toLowerCase() === "quit") return message.reply("Bye!"); // The return is doesn't work });

¿Cómo puedo hacer que funcione?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Una simple declaración de return no detendrá al coleccionista. Simplemente hace que el resto del código dentro de esa función no se ejecute. Pero, si hay un nuevo mensaje entrante, la función de devolución de llamada se ejecuta nuevamente.

Sin embargo, puede usar el método Collector#stop() que detiene el recopilador y emite el evento end . También puede agregar un motivo por el cual finaliza el recopilador.

Echa un vistazo al código a continuación:

 const filter = (m) => m.author.id === message.author.id; const collector = message.channel.createMessageCollector({ filter, max: 5, time: 1000 * 20, }); collector.on('collect', (collected) => { if (collected.content.toLowerCase() === 'quit') { // collector stops and emits the end event collector.stop('user cancelled'); // although the collector stopped this line is still executed return message.reply('Bye!'); } // this line only runs if the above if statement is false message.reply(`You said _"${collected.content}"_`); }); // listening for the end event collector.on('end', (collected, reason) => { // reason is the one you passed above with the stop() method message.reply(`I'm no longer collecting messages. Reason: ${reason}`); });

ingrese la descripción de la imagen aquí

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!