Problem with .name in command handler


#1

Hello. I have a problem with a .name in my bot’s command handler code.

Error:

TypeError: Cannot read property 'name' of undefined

My code of a command handler:

fs.readdir("./commands/", (err, files) => {

if (err) console.log(err);

let jsfile = files.filter(f => f.split(".").pop() === "js")
if(jsfile.length <= 0){
console.log("Nie można znaleźć komend.");
return;
}

jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`Komenda ${f} została załadowana!`);
bot.commands.set(props.help.name, props); //props.help.name
});

});

#2

Every file in commands must have the following:

exports.help = {
    name: 'filenameOrWhatever'
};

#4

please help me. IT’S STILL NOT WORKING!!!


#5

Hello @PoProstuBartek, welcome to the Glitch Forums!

Can you post the contents of the command js file that seems to be causing the issue, if you know which one it is? Or give us your project name so we can take a look?


#6

Oh wait… I didn’t coded my commands files. Sorry! It’s propably going to work after filling ALL commands files. :sweat_smile: