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

302
Vistas
How do i stop a specific function in JavaScript? I dont want the whole program to stop
client.on('message', msg => {
  if (msg.content === 'startspam') {
    function spam(){
      msg.channel.send('a')
    }
    setInterval(spam, 2500)
  }
});

client.on('message', msg => {
  if (msg.content === 'stopspam') {
    
  }
});

how to stop the function spam ( sorry I'm new to JavaScript and im trying to learn the basics )

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

0

You can use the clearInterval function on the number that setInterval returns to stop the interval. I added some code below to show how that works.

var interval = setInterval(someFuntion, 200);
clearInterval(interval);
about 4 years ago · Juan Pablo Isaza Denunciar

0

Try clearInterval

const print = () => console.log('alive');
const intervalId = setInterval(print, 1000);
const stopInterval = () => clearInterval(intervalId);
<button onclick='stopInterval()'>Stop</button>

about 4 years ago · Juan Pablo Isaza Denunciar

0

first of all java and javascript are not the same..

and for your question -

you can use this clearInterval().

this function receives the id of the interval you want to stop. and the interval Function returns a unique number so it can used as ID..

the way you do it is somthing like this :

var intervalID = '';

function startInterVal() {
  intervalID = setInterval(() => {
    console.log('Hello')
  }, 1000)
}

function stopInterval() {
  clearInterval(intervalID);
}
<button onClick="startInterVal()">Start</button>

<button onClick="stopInterval()">Stop</button>

hope i helped you :)

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