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

150
Views
Discord.js : commands.map is not a function at ApplicationCommandManager.set

I am encountering a TypeError while trying to set up the commands for my bot. This happens when trying to use commands.set

function setCommands(): void {
  var slashCommandFiles = fs.readdirSync('./commands').filter((file: string) => (file.endsWith('.js') && !forbiddenCommands.includes(file.slice(0, -3))));
  for (const file of slashCommandFiles) {
    const command = require(`./commands/${file}`);
    slashCommands.push(command.data.toJSON());
    if (client.application)
      client.application.commands.set(command.data.name, command); //happens here
    else {
      console.error(client);
      throw new Error("Unable to load the commands");
    }
  }
}

The error message is the following:

C:\Overbot\node_modules\discord.js\src\managers\ApplicationCommandManager.js:147
      data: commands.map(c => this.constructor.transformCommand(c)),
                     ^

TypeError: commands.map is not a function
    at ApplicationCommandManager.set (C:\Overbot\node_modules\discord.js\src\managers\ApplicationCommandManager.js:147:22)
    at setCommands (C:\Overbot\index.js:68:41)
    at C:\Overbot\index.js:108:17
    at step (C:\Overbot\index.js:34:23)
    at Object.next (C:\Overbot\index.js:15:53)
    at C:\Overbot\index.js:9:71
    at new Promise (<anonymous>)
    at __awaiter (C:\Overbot\index.js:5:12)
    at Client.<anonymous> (C:\Overbot\index.js:98:43)
    at Object.onceWrapper (node:events:514:26)

Thing is, it's definitely a function that does exist, since I verified the code and found it with no problem. I don't think this is a semicolon shenanigan either, because I already tested it with and without semicolons everywhere, to the same result.

Is there any way I can make this work ?

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

0

That's not how you set the commands. Use this instead:

client.application.commands.set(slashCommands) 
//I assume slashCommands is an array of ApplicationCommandData, according to your code
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!