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

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

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 Denunciar

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 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