Reputation: 5
const fs = require('fs');
function loadCommands(client) {
fs.readdir('commands/', (err, files) => {
if (err) console.log(err);
const jsfile = files.filter(f => f.split('.').pop() === 'js');
if (jsfile.length <= 0) {
return console.log('Bot Couldn\'t Find Commands in commands Folder.');
}
jsfile.forEach((f, i) => {
const pull = require(`../commands/${f}`);
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name);
});
});
});
}
module.exports = {
loadCommands
}
I don't know why the error it's here it looks great the code...
The error is found in client.commands.set(pull.config.name, pull); and in bot.aliases.set(alias, pull.config.name); show that is undefined.
I need some help here, i'm trying to make a custom prefix for my bot and I really need this code!
Upvotes: 0
Views: 38
Reputation: 108651
One of the files in ../commands/whateverFile.js
doesn't export config
, or does export config
but doesn't put a .name
property on it. You didn't show us any of those files so it's hard to guess at the problem.
You could try this to figure out which file is bad.
jsfile.forEach((f, i) => {
const pull = require(`../commands/${f}`);
if (!pull || !pull.config || !pull.config.name) {
throw new Error (`bogus require file ${f}`)
}
client.commands.set(pull.config.name, pull);
pull.config.aliases.forEach(alias => {
bot.aliases.set(alias, pull.config.name);
});
});
Upvotes: 1