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

677
Views
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 answers
Answer question

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 Report

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