mirror of
https://github.com/SrIzan10/Recluse-Bot.git
synced 2026-05-01 10:55:24 +00:00
Create command.js
This commit is contained in:
35
handlers/command.js
Normal file
35
handlers/command.js
Normal file
@@ -0,0 +1,35 @@
|
||||
const { readdirSync } = require("fs");
|
||||
|
||||
const ascii = require("ascii-table");
|
||||
|
||||
// Create a new Ascii table
|
||||
let table = new ascii("Commands");
|
||||
table.setHeading("Command", "Load status");
|
||||
|
||||
module.exports = (client) => {
|
||||
// Read every commands subfolder
|
||||
readdirSync("./commands/").forEach(dir => {
|
||||
// Filter so we only have .js command files
|
||||
const commands = readdirSync(`./commands/${dir}/`).filter(file => file.endsWith(".js"));
|
||||
|
||||
// Loop over the commands, and add all of them to a collection
|
||||
// If there's no name found, prevent it from returning an error,
|
||||
// By using a cross in the table we made.
|
||||
for (let file of commands) {
|
||||
let pull = require(`../commands/${dir}/${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 there's an aliases key, read the aliases.
|
||||
if (pull.aliases && Array.isArray(pull.aliases)) pull.aliases.forEach(alias => client.aliases.set(alias, pull.name));
|
||||
}
|
||||
});
|
||||
// Log the table
|
||||
console.log(table.toString());
|
||||
}
|
||||
Reference in New Issue
Block a user