Skip to content

Commit

Permalink
Fix subcommand loading
Browse files Browse the repository at this point in the history
- Fixed issue where subcommands file paths are built incorrectly
  • Loading branch information
sethwalker1 authored Dec 8, 2023
1 parent 5daff4b commit 7fef61c
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Client.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,16 @@ 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}`);

// All valid commands must have a data and execute property
if (!('data' in command && 'execute' in command))
return console.warn(`The command at ${filePath} is invalid!`);

resolve(command);
}))
return command;
})
);
}

Expand All @@ -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)) {
Expand Down Expand Up @@ -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);
})
);

Expand Down

0 comments on commit 7fef61c

Please sign in to comment.