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

426
Vistas
Discord.js collector filter is not working?

So, I have this part of the code from a quiz bot made with discord.js.
I set collector filter max: 1, but when 2 or more users reply with the correct answer in the same SECOND, they both get the points and it should be only one user, not 2 or more.

Example of this occurring: Example

The code:

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

0

As you haven't provided the code where the original message is defined, it's hard to find an exact answer to the issue.

One method would be to check the authors ID against the original message, like so:

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

Full example:

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

Replacing <Message> with the original message object.

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