【问题标题】:Auto send message discord.js自动发送消息 discord.js
【发布时间】:2021-04-01 01:33:11
【问题描述】:

我有一个 Discord 的 selfbot 项目(我知道它违反了 ToS,但这只是一个实验,我不会使用它)

我希望 selfbot 在特定频道中每小时发送一条消息,例如“这是一条示例消息”,ID 为 (783651779207626752)

我应该在代码中添加什么以及在哪里添加一些东西?

const Discord = require("discord.js")
const client = new Discord.Client()
const { prefix, token } = require("./config.json")
const fs = require("fs")
const { table, getBorderCharacters } = require("table")


const commands = new Discord.Collection();

let commandFiles

function loadCommands() {
    console.log("loading commands..")
    const startTime = new Date().getTime()

    commandFiles = fs.readdirSync("./commands/").filter(file => file.endsWith(".js"));
    const failedTable = []

    if (commands.size > 0) {
        for (command of commands.keyArray()) {
            delete require.cache[require.resolve(`./commands/${command}.js`)]
        }
        commands.clear()
    }

    for (file of commandFiles) {
        let command
        
        try {
            command = require(`./commands/${file}`);

            let enabled = true;
        
            if (!command.name || !command.description || !command.run) {
                enabled = false;
            }

            if (enabled) {
                commands.set(command.name, command);
            } else {
                failedTable.push([file, "❌"])
            }
        } catch (e) {
            failedTable.push([file, "❌"])
        }
    }
}

loadCommands()

exports.reloadCommands = loadCommands

client.once("ready", () => {
    console.log("logged in as " + client.user.username + "#" + client.user.discriminator)
})

function runCommand(cmd, message, args) {
    args.shift()
    try {
        commands.get(cmd).run(message, args)
    } catch(e) {
        console.log(e)
    }
}

setTimeout(() => {
    client.login(token)
}, 1500)

【问题讨论】:

  • 正如你所说,它是一个 Self Bot,也违反了 Discord 的服务条款,我个人在 2016 年使用 Selfbots,当时他们没有强制执行此问题,但我强烈建议你不要't selfbot 其次;作为开发人员,我们知道“我不会使用它”不太可能被认真对待,服务条款的存在是有原因的。请坚持下去,防止自己被封号。

标签: javascript node.js discord discord.js


【解决方案1】:

您可以创建另一个名为 globalFunctions.js 的文件

添加任何你想作为 IFFE 全局运行的东西

这将确保每个 IFFE 都有自己的代码块

globalFunctions.js


export default globalFunctions(client, channel){
/*
 IFFE
*/

    (function(){
      setInterval(()=>{
         channel.send('some message')
      }, /*Time you want*/)
    })()

// and so on

}

或“如果你想扩大规模,我建议这样做

您可以为每个全局函数添加其他文件,然后添加到全局函数文件中

/*Import other functions*/

import periodicMessage from 'PATH'
export default globalFunctions(client, channel){
   
    periodicMessage(client, channel);


}

只需将此函数导入主文件并在服务器运行后运行它

ma​​in.js

import globalFunctions from 'PATH'

client.once('ready', () => {

    // Your code

    globalFunctions(client, channel)
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-08-25
    • 2020-08-04
    • 2021-01-02
    • 2021-02-05
    • 2020-10-08
    • 2020-06-13
    • 2021-10-17
    相关资源
    最近更新 更多