简体   繁体   English

如何终止 node.js 中的循环?

[英]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".我正在制作一个 discord 机器人,并且我创建了一个命令,每当有人执行命令“,ping @ example”时。 then it would ping @example once every minute until @example stops it, I have created the loop successfully, however.然后它会每分钟ping一次@example,直到@example停止它,但是我已经成功创建了循环。 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()方法清除使用setInterval()方法设置的计时器。

clearInterval(interval);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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