【问题标题】:ReferenceError: "bot" is not defined (Eris) - in my commandsReferenceError:未定义“bot”(Eris)-在我的命令中
【发布时间】:2021-04-02 13:56:09
【问题描述】:

我正在创建一个 Discord 机器人,并且已经取得了很大进展。但是,当我尝试连接我的机器人时,我不断收到此错误:

ReferenceError: 机器人未定义

我的主文件代码是here。我已经定义了常量变量bot 来要求 Eris 库。

但是,当我尝试运行代码时,我的命令代码会抛出上述错误。我尝试使用多个版本的module.exports,但似乎没有任何效果。我的命令代码位于here

【问题讨论】:

标签: node.js discord bots referenceerror eris


【解决方案1】:

bot 常量只存在于主文件中,因此您需要一种方法将其传递给命令文件。您可以使用 bot 作为参数从命令文件中导出函数

const Permissions = require('eris').Constants.Permissions;

module.exports = function(bot){
    // paste in the rest of the commands code
};

然后运行主文件中的函数

require('../src/commands/loader')(bot);

【讨论】:

    猜你喜欢
    • 2021-04-16
    • 2022-01-08
    • 2021-10-28
    • 2021-12-20
    • 2021-08-07
    • 1970-01-01
    • 1970-01-01
    • 2017-04-14
    • 2021-03-01
    相关资源
    最近更新 更多