[英]Receiving a forEach error when requiring and running a directory?
I am recreating my Discord Bot and currently have this code, however, I am receiving an error in which I do not understand on what is throwing it, as it has worked previously before the adding of the new Object.我正在重新创建我的 Discord Bot 并且目前有这个代码,但是,我收到一个错误,我不明白抛出它的原因,因为它在添加新对象之前已经工作过。 The files are there, I require them properly, but it keeps throwing the error.
文件在那里,我正确地需要它们,但它不断抛出错误。
const { Client } = require('discord.js');
const client = new Client({ fetchAllMembers: true });
const { token } = require('./../JSON/config.json');
const bot = {
client: client,
commands: new Map(),
aliases: new Map(),
options: {
productionMode: true,
testingMode: false
},
login: function() {
return client.login("token-here");
},
scoutPrefix: "^",
devPrefix: "$",
staff: [ "id-here" ],
}
[ 'commandHandler', 'eventHandler' ].forEach(h => require(`./Handlers/${h}`)(scout))
bot.login();
//client.login(token);
C:\Users\PC\Documents\Files\Development\Staff Bots\Alpha\Core\core.js:24
[ 'commandHandler', 'eventHandler' ].forEach(h => require(`./Handlers/${h}`)(scout))
^
TypeError: Cannot read property 'forEach' of undefined
at Object.<anonymous> (C:\Users\PC\Documents\Files\Development\Staff Bots\Alpha\Core\core.js:24:38)
[90m at Module._compile (internal/modules/cjs/loader.js:1138:30)[39m
[90m at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)[39m
[90m at Module.load (internal/modules/cjs/loader.js:986:32)[39m
[90m at Function.Module._load (internal/modules/cjs/loader.js:879:14)[39m
[90m at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)[39m
[90m at internal/main/run_main_module.js:17:47[39m
It seems that it interpreted as它似乎被解释为
const bot = {
// ...
}['commandHandler', 'eventHandler'].forEach(...)
To fix the problem, add a semicolon to prevent ambiguity.要解决此问题,请添加分号以防止歧义。
const bot = {
// ...
}; // <<
['commandHandler', 'eventHandler'].forEach(...);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.