From 7fef61c89fcee9c24d09bf869754c46fa4f2aa35 Mon Sep 17 00:00:00 2001 From: Seth W Date: Fri, 8 Dec 2023 02:46:20 -0500 Subject: [PATCH] Fix subcommand loading - Fixed issue where subcommands file paths are built incorrectly --- src/Client.mjs | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/Client.mjs b/src/Client.mjs index d0889c2..b29c149 100644 --- a/src/Client.mjs +++ b/src/Client.mjs @@ -48,7 +48,7 @@ export default class Client { // Load and validate each command asynchronously for better performance return await Promise.all( - commandFiles.map(file => new Promise(async resolve => { + commandFiles.map(async file => { const filePath = path.join(directory, file); const { default: command } = await import(`file://${filePath}`); @@ -56,8 +56,8 @@ export default class Client { if (!('data' in command && 'execute' in command)) return console.warn(`The command at ${filePath} is invalid!`); - resolve(command); - })) + return command; + }) ); } @@ -69,12 +69,8 @@ export default class Client { // Skip invalid commands if (!command) continue; - // Build the command name and subcommand path - const commandName = path.basename( - commandsPath, - path.extname(commandsPath) - ); - const subcommandPath = path.join(subcommandsPath, commandName); + // Build the subcommand path + const subcommandPath = path.join(subcommandsPath, command.name); // Load subcommands if they exist if (fs.existsSync(subcommandPath)) { @@ -122,11 +118,8 @@ export default class Client { }); // Register the event - if (event.once) { - Client.client.once(event.name, handler); - } else { - Client.client.on(event.name, handler); - } + if (event.once) Client.client.once(event.name, handler); + else Client.client.on(event.name, handler); }) );