Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在创建一个 Discord 机器人,而且我已经走了很远。但是,当我尝试连接我的机器人时,我不断收到此错误:
ReferenceError:未定义机器人
我的主文件的代码在这里。我已将常量变量定义bot为需要 Eris 库。
bot
但是,当我尝试运行代码时,我的命令代码会引发上述错误。我尝试使用多个版本,module.exports但似乎没有任何效果。我的命令代码位于此处。
module.exports
该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);