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. 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(...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.