Skip to content

Commit

Permalink
[Fix] Still not working because of Paths :P
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Oct 2, 2021
1 parent da0ea22 commit fa36e98
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 44 deletions.
2 changes: 1 addition & 1 deletion events/guildCreate.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { registerSlashCommands } = require("../deploy-commands");
const { registerSlashCommands } = require("../modules/deploy-commands");

module.exports = {
name: "guildCreate",
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ client.commands = new Collection();
client.logger = logger;

// Register everything...
commandsHelper.registerAllCommands("./commands", client);
commandsHelper.registerAllEvents("./events", client);
commandsHelper.registerAllCommands(__dirname + "/commands", client);
commandsHelper.registerAllEvents(__dirname + "/events", client);
playerEvents(client.player);

// ... and go!
Expand Down
82 changes: 41 additions & 41 deletions modules/commandsHelper.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
/***
* CommandsHelper - Help for commands
*
*
* It may make no sense, but it is ours!
*/
const fs = require("fs");

let commandsHelper = function () {
let api = {}
let api = {};

/**
* Registers all commands in the given subdirectory into the client collection
*
* @param {string} commandsFolder Path to folder that contains all commands
* @param {Client} client The discord client
*/
api.registerAllCommands = function (commandsFolder, client) {
const allCommandsFolders = fs.readdirSync(commandsFolder);
/**
* Registers all commands in the given subdirectory into the client collection
*
* @param {string} commandsFolder Path to folder that contains all commands
* @param {Client} client The discord client
*/
api.registerAllCommands = function (commandsFolder, client) {
const allCommandsFolders = fs.readdirSync(commandsFolder);

for (const folder of allCommandsFolders) {
const commandFiles = fs
.readdirSync(`${commandsFolder}/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`${commandsFolder}/${folder}/${file}`);
command.category = folder;
client.commands.set(command.data.name, command);
}
}
for (const folder of allCommandsFolders) {
const commandFiles = fs
.readdirSync(`${commandsFolder}/${folder}`)
.filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const command = require(`${commandsFolder}/${folder}/${file}`);
command.category = folder;
client.commands.set(command.data.name, command);
}
}
};

/**
* Registers all events in the given subdirectory on the client
*
* @param {string} eventFolder Path to folder that contains all events
* @param {Client} client The discord client
*/
api.registerAllEvents = function (eventFolder, client) {
const eventFiles = fs
.readdirSync(eventFolder)
.filter((file) => file.endsWith(".js"));
/**
* Registers all events in the given subdirectory on the client
*
* @param {string} eventFolder Path to folder that contains all events
* @param {Client} client The discord client
*/
api.registerAllEvents = function (eventFolder, client) {
const eventFiles = fs
.readdirSync(eventFolder)
.filter((file) => file.endsWith(".js"));

for (const file of eventFiles) {
const event = require(`${eventFolder}/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
for (const file of eventFiles) {
const event = require(`${eventFolder}/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
};

return api;
}
return api;
};

module.exports.commandsHelper = commandsHelper();
module.exports.commandsHelper = commandsHelper();

0 comments on commit fa36e98

Please sign in to comment.