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

194
Vistas
Node.js use setInterval & clearInterval on a function

Hello is there a way to call a function with setInterval and clear the interval later?

Example: When I write in a chat !start the interval function should start with a interval. And when I write !stop in the chat the function with the interval on it should stop.

This is my function:

function abb(channel){
    console.log('Auto-Ban-Bot Timer running...')
    getChannelViewers(channel.replace('#','')).then(
        promise => {
            var vierwernames = promise.chatters.viewers;
            vierwernames.forEach(element => {
                checkFriendlyBots(element)
            });
        }
    );
}

I've tried many things but only got the !start command working, not the !stop command.

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

0

This is exactly what clearInterval() method does. It clears a timer set with the setInterval() method.

Check out this example:

const interval = setInterval(myTimer, 1000);
let i = 0;

function myTimer() {
  console.log(i++);
  if (i === 5){
    stop();
  }
}

function stop() {
  clearInterval(interval);
}

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