Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

432
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda