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

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

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 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!