【问题标题】:Discord Daily greeting不和谐每日问候
【发布时间】:2021-03-31 13:06:38
【问题描述】:

我正在努力寻找有关此问题的任何教程或帮助。我只是希望机器人每天在频道中发送一条消息,说“今天是 {星期几}”。有谁知道怎么做?

【问题讨论】:

    标签: javascript discord


    【解决方案1】:

    获取星期几

    const now = new Date();
    const weekdays = [
      "Sunday",
      "Monday",
      "Tuesday",
      "Wednesday",
      "Thursday",
      "Friday",
      "Saturday"
    ];
    const day = weekdays[now.getDay()];
    console.log(day);

    每天发送

    This very good answer 似乎回答了你的问题。 适用于您的问题:

    const cron = require("cron");
    
    function getDay() {
      return [
        "Sunday",
        "Monday",
        "Tuesday",
        "Wednesday",
        "Thursday",
        "Friday",
        "Saturday",
      ][new Date().getDay()];
    }
    
    function greeting() { // To be fired
      const channel = your_channel;
      return channel.send(`Today is ${getDay()}!`);
    }
    
    const dailyGreeting = new cron.CronJob("00 00 08 * * *", greeting); // Fires every day at 08:00:00 AM
    dailyGreeting.start(); // Start the job
    

    【讨论】:

      猜你喜欢
      • 2021-07-18
      • 2020-04-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-09
      • 2021-11-30
      • 2020-08-20
      • 2022-11-10
      相关资源
      最近更新 更多