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
Discord.js command timeout

I have a command where it asks a question and gives different responses based on the answer, and that part works, but the command doest end, meaning that if you reply to a new instance of the command, the first instance and the new instance will reply. I tried different timeout functions but nothing worked. here's the code:

module.exports = {
name: 'test',
description: "test comand",
execute(message, args, Discord) {
    message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")
    console.log(message.author.id)
    const collector = new Discord.MessageCollector(message.channel, m => m.author.id === member, { time: 10000 });
    collector.on('collect', message => {
        if (message.content.toUpperCase() == "YES") {
            message.channel.send("Let's Go! It worked!");
    } else if (message.content.toUpperCase() == "NO") {
            message.channel.send( "Task failed successfully.");
     } else if (message.content.toUpperCase() == "MAYHAPS") {
            message.channel.send("ERROR: IT WORKED ANYWAY");
        }
})
}

}

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

0

I think the problem is that you are not stopping the collector, try:

collector.stop();

after all the conditions.

Also, you need to check that the message sent is from a user and not from the bot, since you are not awaiting the first message to send before starting the collector.

message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")

The colletor is collecting that message, which is from the bot, so you are stopping the collector with the bot message, not giving a chance to reply.

Final result:

collector.on("collect", async (message) => {
    if (message.content.toUpperCase() == "YES") {
        await message.channel.send("Let's Go! It worked!");
    } else if (message.content.toUpperCase() == "NO") {
        await message.channel.send("Task failed successfully.");
    } else if (message.content.toUpperCase() == "MAYHAPS") {
        await message.channel.send("ERROR: IT WORKED ANYWAY");
    }
    if (!message.author.bot) collector.stop();
});

In case you don't want to check if the message is from a bot, you can await the first message like this:

module.exports = {
    name: 'test',
    description: "test comand",
    async execute(message, args, Discord) {
        await message.channel.send("Do you want to test this command?\n `Yes`, `No` or `Mayhaps`")
        console.log(message.author.id)
        const collector = new Discord.MessageCollector(message.channel, m => m.author.id === member, { time: 10000 });
        collector.on('collect', message => {
            if (message.content.toUpperCase() == "YES") {
                message.channel.send("Let's Go! It worked!");
            } else if (message.content.toUpperCase() == "NO") {
                message.channel.send( "Task failed successfully.");
            } else if (message.content.toUpperCase() == "MAYHAPS") {
                message.channel.send("ERROR: IT WORKED ANYWAY");
            }
        })
    }
}
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!