我试图让机器人在特定时间写消息。例子:
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)