小编Mez*_*ezz的帖子

如何每天在特定时间发送消息?

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

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!");
  }
});
Run Code Online (Sandbox Code Playgroud)

不幸的是,它只有在我触发另一个命令时才有效,例如:

if (message.content.startsWith("!ping")) {
  message.channel.send("pong!");
}
Run Code Online (Sandbox Code Playgroud)
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(); …
Run Code Online (Sandbox Code Playgroud)

javascript discord.js

4
推荐指数
1
解决办法
2万
查看次数

标签 统计

discord.js ×1

javascript ×1