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

129
Views
adding more folder for new code resulting error on command handler

So I have likes 6 folder on my bot commands, meanwhile I need to manually add "the folder name" into the command.js (so bot can run the command on those folders) but when I add more than 4 folder name in the code, it said "Cannot read properties of undefined (reading 'name'), meanwhile if it's only 4 or less it works fine, is there a way so the bot can run those folders without adding the name into handlers ?

here's my folder that I had currently : https://i.stack.imgur.com/KrO0J.png

here's the error after I add more than 4 folders on the handler : https://i.stack.imgur.com/XYClm.png

and here's the code I use for the command handler:

const { readdirSync } = require("fs")

module.exports = (bot) => {
    const load = dirs => {
        const commands = readdirSync(`./commands/${dirs}/`).filter(d => d.endsWith('.js'));
        for (let file of commands) {
            let pull = require(`../commands/${dirs}/${file}`);
            bot.commands.set(pull.config.name, pull);
            if (pull.config.aliases) pull.config.aliases.forEach(a => bot.aliases.set(a, pull.config.name));
          };
        };
        ["mod", "utility", "misc", "department"].forEach(x => load(x));
};

about 4 years ago · Juan Pablo Isaza
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!