我想知道如何制作一个不协调的机器人,该机器人将在太平洋标准时间星期一,星期三和星期五的9:45重复一条消息。
我正在使用discord.js,并且消息运行正常,只是不知道如何在特定的时间和日期发送消息。
答案 0 :(得分:0)
由于您已经设置了消息,因此以下是在特定时间触发消息的方法。
let timer = setInterval(function() {
const now = new Date(); // for reference, PST is UTC-8, and I'm assuming you don't want to account for the nightmare that is daylight savings time
if (now.getDay() == 1 || now.getDay() == 3 || now.getDay() == 5) { // check if it's monday, wednesday, or friday
if (now.getUTCHours() - 8 == 9 && now.getUTCMinutes() == 45) { // confirm that it's 5:45 pm UTC, or 9:45 am PST
sendTime(); // note that this won't say what day in particular it is, but that's probably fine
}
}
}, 60 * 1000); // fire the function only every minute to prevent insane lag.
我可能应该建议做一些调整,以确保机器人不会在时钟9:46发出时发送时间消息,前提是您对此很在意。