【发布时间】:2020-08-08 03:20:24
【问题描述】:
以下是相关代码:
var Started = "no";
// other stuff
// HERE IS WHERE THE CODE IS
client.on('ready', () => {
var channel = client.channels.find(channel => channel.id === '740342329973538858');
console.log("we in bois");
setInterval(() => {
channel.send({
embed: {
meesage
}
});
}, 10000);
});
// other stuff
if (msg.content === "start") {
var Started = 'yes';
console.log = 'no';
}
// another one of the above for no
我不知道如何制作一个 if 语句来始终检查是否已启动是或否。我需要在是时开始,在否时停止(我说的代码是HERE IS WHERE THE CODE IS)
【问题讨论】:
-
我没有特别处理不和谐,但我想你的逻辑应该包含某种事件监听器。
-
是的,但我不知道如何在我发送停止消息后阻止它发送嵌入。
-
setInterval 将继续运行。一种解决方案是在
channel.send之前放置一个if (Started === "yes")。此外,您应该只在代码顶部声明一次var Started。其他引用不应包括var。 -
另一种更优选的解决方案是将
setInterval结果分配给一个变量,然后调用clearInterval(varname)将其从DOM 中删除。
标签: javascript node.js discord discord.js