【问题标题】:Send message every x time on x day (Discord.js)在 x 天每 x 次发送消息 (Discord.js)
【发布时间】:2020-12-15 15:39:11
【问题描述】:

我想知道如何制作一个不和谐机器人,它会在太平洋标准时间每周一、周三和周五上午 9:45 重复一条消息。

我正在使用 discord.js,我的消息工作得很好,只是不知道如何在特定时间和日期发送消息。

【问题讨论】:

标签: discord bots discord.js


【解决方案1】:

由于您已经设置了消息,以下是您在特定时间触发消息的方式。

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 时发送时间消息,假设您关心这一点。

【讨论】:

  • 我该如何开始呢?它会继续重复直到机器人关闭吗?
  • 它会自动启动,是的,它会每分钟重复一次。抱歉耽搁了。
猜你喜欢
  • 2020-06-13
  • 1970-01-01
  • 2016-05-01
  • 2018-06-27
  • 1970-01-01
  • 2018-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多