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

673
Visualizações
Error: ENOENT: no such file or directory, scandir '../commands' discord.js

I wanted to read all of the files that are in a Folder, but I got an error. My code:

        const Commands = []
        readdirSync("../commands").forEach((folder) => {
            readdirSync(`../commands/${folder}`).forEach((file) => {
                const command = require(`../commands/${folder}/${file}`);
                if (!command.name) return;
                Commands.push(command);
            })
        })

The error:

<rejected> Error: ENOENT: no such file or directory, scandir '../commands'

I am using discord.js v13 and node.js v16 Notes: main.js is not in the commands folder.

enter image description here

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

In node, the relative paths for fs functions are from the path of the entrypoint file (your index.js), so in this case, instead of putting ../commands (which would be correct if you started your command with commands.js, but you have not), you need to put ./commands (I am assuming the commands folder is in the same folder as your index.js)

about 4 years ago · Santiago Trujillo Relatório

0

I found the solution myself. I just needed to replace that code with this one:

const Commands = []
        readdirSync("./commands").forEach((file) => {
                const command = require(`../commands/${file}`);
                if (!command.name) return;
                Commands.push(command);

        })
about 4 years ago · Santiago Trujillo 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