Discord.js command.name.toLowerCase() is not working


client.commands = new Discord.Collection();
const cooldowns = new Discord.Collection();
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
	const command = require(`./commands/${file}`);
	client.commands.set(command.name.toLowerCase(), command);//Errors at command.name.toLowerCase()

Command is a file and command.name is it’s name in string
Help With:
I just want to convert The string (command.name.toLowerCase()) but it sends an error i have also tried in VScode but it sends error there also error is same
TypeError: Cannot read property ‘toLowerCase’ of undefined


First of all, that is a nice question!

.toLowerCase() works only with strings, so can you do console.log(typeof command.name) and paste the result here?


Ok give me a minute please

1 Like

So it’s different from what i thought Actually
it printed string for every line but in last line it said undefined

I see, can you do console.log(command) and also paste the result here?

1 Like

I actually found it out i didn’t wrote name for 1 of the commands

1 Like

Maybe one of the command files might be missing the name property.

1 Like

Oh, we said almost the same thing at the same time. :joy::grin:

1 Like