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

133
Views
Command Handler's file reading doesn't work

so basically, I have followed a video (from IGP) on how to make a command handler for a bot. and I can't figure out why it doesn't work (Tomfoolery is the folder for commands)

client.commands = new Collection();
const commands = fs.readdirSync("./Tomfoolery/").filter(file => file.endsWith(".js"))
for(file of commands) {
    const commandName = file.split(".")[0]
    const command = require('./Tomfoolery/'+commandName)
    client.commands.set(commandName, command)
}

I tried npm rebuild node-sass and npm rebuild node-sass --force and similar stuff, and it still gives me: Error: ENOENT: no such file or directory, scandir './Tomfoolery/' (even though Tomfoolery IS on the same folder as the bot.js file)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Make sure you are accessing the correct path and prepending the path with __dirname will fix the issue

client.commands = new Collection();
const commands = fs.readdirSync(__dirname+"/Tomfoolery/").filter(file => file.endsWith(".js"))
for(file of commands) {
    const commandName = file.split(".")[0]
    const command = require(__dirname+'/Tomfoolery/'+commandName)
    client.commands.set(commandName, command)
}
about 4 years ago · Juan Pablo Isaza 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!