Javascript Discord.js与时间相关的事件

Javascript Discord.js与时间相关的事件,javascript,discord,Javascript,Discord,我试图让机器人在特定的时间写消息。例如: const Discord = require("discord.js"); const client = new Discord.Client(); client.on("ready", () => { console.log("Online!"); }); var now = new Date(); var hour = now.getUTCHours(); var minute = now.getUTCMinutes(); clien

我试图让机器人在特定的时间写消息。例如:

const Discord = require("discord.js");
const client = new Discord.Client();
client.on("ready", () => {
    console.log("Online!");
});
var now = new Date();
var hour = now.getUTCHours();
var minute = now.getUTCMinutes();
client.on("message", (message) => {
    if (hour === 10 && minute === 30) {
        client.channels.get("ChannelID").send("Hello World!");
    }
});
不幸的是,它只在我触发另一个命令时起作用,如:

if (message.content.startsWith("!ping")) {
    message.channel.send("pong!");
}
-> pong
-> Hello World!
因此它不会自动工作。

使用setInterval()


记住把它放在
客户机中。在(“message”,“message)=>{
事件中

好吧,现在只要触发了“if”,它就会不断地发出垃圾邮件
function sendsomeMessage() {
client.channels.get("id here").send("Hello world!")
}
setInterval(sendsomeMessage, time in miliseconds here)