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:
["command"].forEach(handler => {
require(`./handler/${handler}`)(client);
})
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());
}
Thanks to @CherryDT I realized I just had to remove readdirSync("./commands/").forEach(dir => {}); to fix my handler.