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

141
Views
How to fix handler duplicating commands list

I have a handler which log commands list in console using ascii-table, but list of my commands gets duplicated, for example if I have 10 commands - list gets duplicated 10 times (image). I use discord.js v12.5.3 and here is my code:

index

["command"].forEach(handler => {
    require(`./handler/${handler}`)(client);
})

command.js (handler file)

const { readdirSync } = require("fs");

const ascii = require("ascii-table");

let table = new ascii("Commands");
table.setHeading("Command", "Load status");

module.exports = (client) => {
  readdirSync("./commands/").forEach(dir => {
        const commands = readdirSync(`./commands/`).filter(file => file.endsWith(".js"));
        for (let file of commands) {
            let pull = require(`../commands/${file}`);
    
            if (pull.name) {
                client.commands.set(pull.name, pull);
                table.addRow(file, '✅');
            } else {
                table.addRow(file, `❌  -> missing a help.name, or help.name is not a string.`);
                continue;
            }
            if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name));
        }
    });
    // Log the table
    console.log(table.toString());
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Thanks to @CherryDT I realized I just had to remove readdirSync("./commands/").forEach(dir => {}); to fix my handler.

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!