Skip to content

Commit

Permalink
[Enahancement] Deleted loopAndRequire function and categorized the he…
Browse files Browse the repository at this point in the history
…lp command in a better way!
  • Loading branch information
naseif committed Sep 4, 2021
1 parent 520a815 commit 4bf0b4e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 52 deletions.
42 changes: 13 additions & 29 deletions commands/misc/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,22 @@ module.exports = {
await interaction.deferReply();
const category = interaction.options.getString("category");

function printHelpByCollection(collection) {
const commands = collection.map(
(command) =>
"`" +
`/${command.data.name} :` +
"`" +
" " +
`${command.data.description}`
);
function printHelpByCollection(collection, category) {
const commands = collection
.filter((item) => item.category === category || category === null)
.map((command) => {
return (
"`" +
`/${command.data.name} :` +
"`" +
" " +
`${command.data.description}`
);
});
return commands;
}

let help;
switch (category) {
case "admin":
help = printHelpByCollection(client.commands.admin);
break;
case "fun":
help = printHelpByCollection(client.commands.fun);
break;
case "anime":
help = printHelpByCollection(client.commands.anime);
break;
case "music":
help = printHelpByCollection(client.commands.music);
break;
case "misc":
help = printHelpByCollection(client.commands.misc);
break;
default:
help = printHelpByCollection(client.commands);
}
help = printHelpByCollection(client.commands, category);

const embed = {
color: "#9dcc37",
Expand Down
12 changes: 1 addition & 11 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,6 @@ const { Player } = require("discord-player");
const player = new Player(client);
client.player = player;
client.commands = new Collection();
const admin = (client.commands.admin = new Collection());
const fun = (client.commands.fun = new Collection());
const music = (client.commands.music = new Collection());
const misc = (client.commands.misc = new Collection());
const anime = (client.commands.anime = new Collection());

findAndRequire("commands/admin", ".js", admin);
findAndRequire("commands/anime", ".js", anime);
findAndRequire("commands/fun", ".js", fun);
findAndRequire("commands/music", ".js", music);
findAndRequire("commands/misc", ".js", misc);

// All commands!
const allCommandsFolders = fs.readdirSync("./commands");
Expand All @@ -37,6 +26,7 @@ for (const folder of allCommandsFolders) {
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`./commands/${folder}/${file}`);
command.category = folder;
client.commands.set(command.data.name, command);
}
}
Expand Down
12 changes: 0 additions & 12 deletions modules/loopAndRequireCommands.js

This file was deleted.

0 comments on commit 4bf0b4e

Please sign in to comment.