简体   繁体   中英

How do I terminate a loop in node.js?

I'm making a discord bot, and I created a command where whenever someone executes the command ",ping @ example". then it would ping @example once every minute until @example stops it, I have created the loop successfully, however. I can't terminate the loop.

var interval = setInterval (function () {
  const user = message.mentions.users.first();
            message.channel.send('You have been pinged!' + '\n' + '<@' + user + '>')

        }, 1 * 60000);

Use clearInterval() method which clears a timer set with the setInterval() method.

clearInterval(interval);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM