我需要在 discord.js 中停止循环的示例

I need example to stopping loop in discord.js

我想结束循环或限制消息。

我不知道如何停止循环。 请帮忙

比如我想做的

let timer = setInterval(function(){    
if(command = "loop")
message.channel.send("test")
       }, sec * 1000)
if(command = "stoploop")
//i need example to stopping the loop

使用clearInterval()停止运行间隔。

let timer = setInterval(function() {
  if(command === "loop")
    message.channel.send("test")
}, sec * 1000)

if(command === "stoploop") {
  clearInterval(timer);
}

请记住,每秒向频道发送一条消息都是对 Discord API 的滥用。长时间执行此类行为可能会使 Discord 因 API 滥用而禁止您的机器人。