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

429
Views
¿El filtro del colector Discord.js no funciona?

Entonces, tengo esta parte del código de un bot de prueba hecho con discord.js .
Configuré el filtro de colector máximo: 1, pero cuando 2 o más usuarios responden con la respuesta correcta en el mismo SEGUNDO, ambos obtienen los puntos y debe ser solo un usuario, no 2 o más.

Ejemplo de que esto ocurra:Ejemplo

El código:

 const filter = (m) => !m.author.bot && m.content.toLowerCase() == current.answer.toLowerCase(); const collector = message.channel.createMessageCollector({ filter, max: 1, time: 45000 }); collector.on('collect', async m => { if (stop == true) return; if (m.content == null || current.answer == null || m.content.toLowerCase() != current.answer.toLowerCase()) return; collector.stop(); remaining = Date.now() - time; points = remaining <= 5000 ? 10 : (remaining <= 15000 ? 8 : remaining <= 25000 ? 6 :(remaining < 35000 ? 4 : 2)); message.channel.send(`Correct! The answer is **${current.answer}**\n**${m.author.tag}**! You got **${points}** points!`).catch((err) => {console.log(err)}); if (fs.existsSync(`./system/users/${m.author.id}.json`)) { data = JSON.parse(fs.readFileSync(`./system/users/${m.author.id}.json`)); data.total += points; data.current += points; data.tag = m.author.tag; fs.writeFileSync(`./system/users/${m.author.id}.json`, JSON.stringify(data, null, 4)); } else { fs.writeFileSync(`./system/users/${m.author.id}.json`, JSON.stringify({ "id": m.author.id, "tag": m.author.tag, "current": points, "total": points }, null, 4)); } await wait(5000); return(md('NEXT')); });
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Como no proporcionó el código donde se define el mensaje original, es difícil encontrar una respuesta exacta al problema.

Un método sería comparar el ID del autor con el mensaje original, así:

 const filter = (m) => m.author.id === <Message>.author.id

Ejemplo completo:

 const filter = (m) => !m.author.bot && m.content.toLowerCase() == current.answer.toLowerCase() && m.author.id === <Message>.author.id;

Reemplazando <Message> con el objeto de mensaje original.

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!