【问题标题】:My discord bot isn't coming online - discord v13我的不和谐机器人没有上线 - 不和谐 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);
});

【问题讨论】:

    标签: node.js discord bots


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2018-03-20
      • 2021-09-30
      • 2019-04-13
      • 2023-04-04
      • 2022-10-24
      • 2018-11-10
      • 1970-01-01
      • 1970-01-01
      • 2017-04-26
      相关资源
      最近更新 更多