自动反应消息 discord.js

Posted

技术标签:

【中文标题】自动反应消息 discord.js【英文标题】:Auto reaction message discord.js 【发布时间】:2021-03-31 17:39:03 【问题描述】:

如何在 ID 为 731634178029912096 的特定频道中创建每 2.5 小时运行一次的自动消息代码?

(我对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)
        )

    

【问题讨论】:

【参考方案1】:

您的问题是在命令文件中执行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 仅适用于该服务器中的特定频道

【讨论】:

以上是关于自动反应消息 discord.js的主要内容,如果未能解决你的问题,请参考以下文章