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

214
Views
TypeError: Cannot read property 'has' of undefined // Discord.js

So, I was creating a bot for my Discord server. And I got this error. Please remember that I am an amateur :). Thanks in advance, appreciate it^^.

 const config = require('../config.js');
 module.exports = message => {
  let client = message.client;
  if (message.author.bot) return;
  if (!message.content.startsWith(config.prefix)) return;
  let command = message.content.split(' ')[0].slice(config.prefix.length);
 let params = message.content.split(' ').slice(1);
 let cmd;
 if (client.commands.has(command)) {
   cmd = client.commands.get(command);
 } else if (client.aliases.has(command)) {
   cmd = client.commands.get(client.aliases.get(command));
 };
 if (cmd) {
   if(!message.guild) {
     if(cmd.config.guildOnly === true) {
       return;
     };
   };
   if (cmd.config.permLevel) {
     if(cmd.config.permLevel === "BOT_OWNER") {
  if(!config.geliştiriciler.includes(message.author.id)) {
       message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
       return;
  }
     }
       if(!message.member.hasPermission(cmd.config.permLevel)) {
     message.channel.send(`Bu komutu kullanabilmek için \`${cmd.config.permLevel}\` yetkisine sahip olmalısın.`).then(msg => msg.delete({timeout: 3000}));
    return;
     };
   };
   cmd.run(client, message, params);
};
};
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

At line no 7, please try this

const cmd =
  message.client.commands.get(command) ||
  message.client.commands.find(
    (cmd) => cmd.aliases && cmd.aliases.includes(command) // if you're also using aliases
  );

if (!command) return;
about 4 years ago · Juan Pablo Isaza Report

0

Add some booleans for checking if client.commands/client.aliases is undefined.

if (client.commands && client.commands.has(command)) {
      cmd = client.commands.get(command);
    } else if (client.aliases && client.aliases.has(command)) {
      cmd = client.commands.get(client.aliases.get(command));
    };
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!