Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

151
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda