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

321
Vistas
DiscordJS: Why is the bot sending more messages as I run the command multiple times?

The code below is wrapped in a class that gets called when specific commands is ran, for example !dm. When I run !dm after starting the bot, it normally sends a message and waits for the user to reply back to the sent message(code below). When I run !dm the second time, it sends a message two times. If I run !dm once more, it sends the message 3 times and so on... Why is this happening and how can I fix it?

this.client.on("messageCreate", function (msg) {
            if (msg.author.bot || msg.channel.type !== "DM") return
            console.log("something")
})

(This is the shortened code)

Full code: PasteHub

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

I think that would be the default behaviour, because the bot will always be listening to the messageCreate event. I think you would need some kind of state for the bot, for eg:

If user1 typed !DM, you would store that info somewhere, like:

const botStates = [];

// Message event closure {
botStates.push({
    user: user.name, // example
    bot_state: 'waiting',
})
// }

And then you could check that state each time the event triggers the closure, and if the state for that user is waiting, you would not send the message.

about 4 years ago · Juan Pablo Isaza Denunciar

0

This might be due to you storing two client events inside of the each other.

Make sure that you are not storing your messageCreate inside of another event.

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