I'm working on discord.js bot V13 and I came across this error
Code:
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()
}
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 Error:
TypeError: Cannot read property ‘toLowerCase’ of undefined
Any information please do not hesitate to ask.
Use .toLowerCase() in your event
Eg:
client.on("messageCreate", async message =>{
if(!message.content.startsWith(prefix)) return;
const args = message.content.slice(prefix.length).trim().split(' ')
const cmd = args[0].toLowerCase()
const command = client.commands.get(cmd)
if(!command) return;
try{
await command.execute(message, args)
} catch(e){
console.log(e)
}
})