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

196
Vistas
Discord.js using interval and clearinterval

Why is my code not working? I try when someone says: spam the bot begins spamming (it does but it will not stop) How can I fix this problem?

client.on("message", msg => {
  

let interval;

if (msg.content === 'yoyo') { 
  // ...
  if (!interval) {
    interval = setInterval(function() {
      msg.channel.send('yo')
        .catch(console.error);
    }, 1 * 5000);
  } else {
    message.channel.send('yo already running');
  }
}

if (msg.content === 'stop') {
  clearInterval(interval);
  interval = 1 * 1000000;
}
});
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The awnser to my question was to remove the let interval outside my handler. It was creating a new interval at each 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