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

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

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