Skip to content

Commit

Permalink
[New] Categorized the commands groups, added new collection for each …
Browse files Browse the repository at this point in the history
…group
  • Loading branch information
naseif committed Sep 2, 2021
1 parent e4b6039 commit a1e8cc4
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,32 @@ const client = new Client({
],
restRequestTimeout: 30000,
});

client.commands = new Collection();
const { findAndRequire } = require("./modules/loopAndRequireCommands");
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());
// Admin Commands
findAndRequire("commands/admin", ".js", admin);

// Fun Commands
findAndRequire("commands/fun", ".js", fun);

const commandFolders = fs.readdirSync("./commands");
// Music Commands
findAndRequire("commands/music", ".js", music);

for (const folder of commandFolders) {
// Misc Commands
findAndRequire("commands/misc", ".js", misc);

// All commands!

const allCommandsFolders = fs.readdirSync("./commands");

for (const folder of allCommandsFolders) {
const commandFiles = fs
.readdirSync(`./commands/${folder}`)
.filter((file) => file.endsWith(".js"));
Expand All @@ -28,6 +45,7 @@ for (const folder of commandFolders) {
}
}

// Loop through the events and require them
const eventFiles = fs
.readdirSync("./events")
.filter((file) => file.endsWith(".js"));
Expand All @@ -41,6 +59,7 @@ for (const file of eventFiles) {
}
}

// Loop through the discord-player events and require them
const botEvents = fs
.readdirSync("./playerEvents")
.filter((file) => file.endsWith(".js"));
Expand All @@ -50,6 +69,7 @@ for (const file of botEvents) {
player.on(event.name, event.execute);
}

// Initialize the client on interaction
client.on("interactionCreate", async (interaction) => {
if (!interaction.isCommand()) return;
const command = client.commands.get(interaction.commandName);
Expand All @@ -65,4 +85,5 @@ client.on("interactionCreate", async (interaction) => {
});
}
});

client.login(token);

0 comments on commit a1e8cc4

Please sign in to comment.