Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/473.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript discord bot如果station仅当veriable等于yes时,bot发送嵌入_Javascript_Node.js_Discord_Discord.js - Fatal编程技术网

Javascript discord bot如果station仅当veriable等于yes时,bot发送嵌入

Javascript discord bot如果station仅当veriable等于yes时,bot发送嵌入,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,以下是相关代码: 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");

以下是相关代码:

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语句来始终检查启动是否为是或否。我需要在是时启动,在不是时停止。我所说的代码就是代码所在的位置。

设置间隔将继续运行。一种解决方案是在channel.send之前放置if start==yes。此外,您应该只在代码顶部声明var启动一次。附加参考不应包括9分钟前的变量–h0r53

在您的情况下,设置间隔将在定义的间隔上保持运行,每10秒一次。一种解决方案是在channel.send之前放置if start==yes。另一种更可取的解决方案是将setInterval结果分配给变量,并调用clearIntervalvarname将其从DOM中删除


作为旁注,您应该只在代码顶部声明var启动一次。其他引用不应包括var.

我对discord没有做太多特别的处理,但我认为您的逻辑应该包含某种事件侦听器。是的,但我不知道如何在发送停止消息后阻止它发送嵌入。setInterval将继续运行。一种解决方案是在channel.send之前放置if start==yes。此外,您应该只在代码顶部声明var启动一次。其他引用不应包括var。另一个更可取的解决方案是将setInterval结果分配给一个变量,并调用clearIntervalvarname将其从DOM中删除。我发表了我的评论作为答案,因为它最终证明是解决方案。这样你就不用在这里引用我的话了。如果你不介意的话,你能把这个问题标记为已回答吗?