TypeError: Cannot read property 'filter' of undefined

Joined
Jun 10, 2019
Messages
1
Reaction score
0
I have a probleme in coding a discord bot ...

TypeError: Can not read property 'filter' of undefined

bot.command = new Discord.Collection ();
fs.readdir ('./ comands /', (err, files) => { if (err) console.log (err);
let jsFile = files.filter (f => f.split ("."). pop () === "js");
if (jsFile.lenght <= 0) { console.log ("I can not find the command");
return;
}
jsFile.forEach ((f, i) => { let props = require (`./commands / $ {f}`);
bot.command.set (props.help.name, props);
}); });
 
Joined
Jul 12, 2019
Messages
3
Reaction score
0
My point of view you have to go through this one may this one help you to fix the issue.

bot.commands = new Discord.Collection();

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("Couldn't find commands.");
return;
}

jsfile.forEach((f, i) =>{
let props = require(`./commands/${f}`);
console.log(`${f} loaded!`);
bot.commands.set(props.help.name, props);
});

});
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top