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

120
Views
discord.js keeps receiving TypeError: Cannot read property 'name' of undefined
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.data.name, command);
}

I keep on getting an error

TypeError: Cannot read property 'name' of undefined

and it has been working flawlessly until now. I tried to console.log(command.data) but I can't seem to find what's wrong...

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

0

Try replacing command.data.name by command.name.

Your code should work if you have this :

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}
about 4 years ago · Juan Pablo Isaza Report

0

This error is telling that the command.data.name line doesn't exists in the file. So this error does not show up because of your index.js file but because one of the files that you are trying to read commands folder. You'll need to make sure that you have added in every file that is being read in the index.js (so in your case all the files in your commands file) in the module.exports the following json line:

module.exports = {
     data: {
         name: 'command_name'
     },
     ....
}
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!