我正在创建一个 Discord 机器人,而且我已经取得了很大进展。但是,当我尝试连接我的机器人时,我不断收到此错误:
<块引用>ReferenceError: bot 未定义
我的主文件的代码是 here。我已经定义了常量变量 bot
来要求 Eris 库。
但是,当我尝试运行代码时,我的命令代码会抛出上述错误。我尝试使用多个版本的 module.exports
但似乎没有任何效果。我的命令代码位于 here。
答案 0 :(得分:0)
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);