Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda