我的不和谐机器人没有上线 - 不和谐 v13

Posted

技术标签:

【中文标题】我的不和谐机器人没有上线 - 不和谐 v13【英文标题】:My discord bot isn't coming online - discord v13 【发布时间】:2021-11-18 09:00:54 【问题描述】:

enter image description herethis bot 已经工作了大约 2 周,突然不上线了?终端根本没有吐出任何错误。它甚至没有记录就绪消息。我对此很陌生,所以如果您确实需要任何进一步的信息,请告诉我:)

edit:: 我已经恢复了几次令牌并自己重新邀请了机器人,但这并没有修复它:/

client.js 文件:

const Client, Intents, Collection  = require('discord.js');
require('dotenv').config();
const client = new Client (intents: [Intents.FLAGS.GUILDS]);
const fs = require('fs');
client.commands = new Collection();

const functions = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
const eventFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
const commandFolders = fs.readdirSync("./src/commands");

(async () => 
    for(file of functions)
        require(`./functions/$file`)(client);
    
    client.handleEvents(eventFiles, "./src/events");
    client.handleCommands(commandFolders, "./src/commands");
    client.on("ready", () => 
        client.user.setActivity('discord.js',  type: 'WATCHING' );  
    );
    client.login(process.env.token);
);

【问题讨论】:

【参考方案1】:

在这段代码中,您正在创建一个异步匿名函数。但是,您只是在定义它。你不叫它!这意味着您的任何命令或事件都没有被加载。为了使它们加载,您必须调用该函数。

(async () => 
    // your loader code here
    client.login(process.env.token);
    // notice the extra () here. That is calling the function.
)();

【讨论】:

以上是关于我的不和谐机器人没有上线 - 不和谐 v13的主要内容,如果未能解决你的问题,请参考以下文章