如何制作一个自动消息代码,每 2.5 小时在特定频道中运行一次,ID 为:731634178029912096?
(我对 discord.js 一无所知)
以下是当前在机器人中的代码:
module.exports = {
name: "help",
description: "view all commands and their description",
run: async (message, args) => {
const { commands } = require("../selfbot.js")
const { prefix } = require("../config.json")
let msg = ""
for (command of commands.keys()) {
msg = msg + prefix + "**" + command + "** " + commands.get(command).description + "\n"
}
await message.edit(msg).then(() => {
setTimeout(() => {
message.delete().catch()
}, 10000)
})
}
}
答案 0 :(得分:0)
您的问题是在命令文件中执行 setTimeout();
。只有在调用命令时才会读取。这是你应该做的:
//index.js
var helpMessage = "whatever is in the message";
const helpChannel = client.channels.cache.get(731634178029912096);
const sendMessage = setInterval(() => helpChannel.send(helpMessage), 9000000); //9000000 = milliseconds in 2.5 hours
注意:使用频道 ID 仅适用于该服务器中的该特定频道。