Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

156
Views
I'm getting error while making an alias system in discord.js

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

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I found the solution myself, all I had to do was:

 if(!command) return message.channel.send('Invalid Command/alias');

after those two lines, it means that if the command name was not correct, or if the alias was not correct, it returns "Invalid command/alias"

about 4 years ago · Juan Pablo Isaza Report

0

Remove the first ! in your find method, it will fix the error

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!