I was making an alias system for my discord bot, and I wanted to say: "if the user entered the wrong command name or alias then return: invalid command/alias", but I'm getting an error:
C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16
if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
^
TypeError: Cannot read properties of undefined (reading 'includes')
at C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16:83
My code:
module.exports = async (message, client, Discord) => {
const prefix = process.env.PREFIX;
if(!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ /);
const cmd = args.shift().toLowerCase();
const command = client.commands.get(cmd) ||
client.commands.find(a => a.aliases && a.aliases.includes(cmd));
if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
}
I'm using discord.js v13 and Node.js v16.14.2
CodePudding user response:
Remove the first !
in your find method, it will fix the error
CodePudding user response:
I found the solution, All I needed to do was:
if(!command) return message.channel.send('Invalid Command/alias');