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

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

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