mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-01-19 17:03:47 +05:00
feat: added handle command func
This commit is contained in:
parent
d4dfec9789
commit
31e75bb08b
1 changed files with 30 additions and 0 deletions
|
@ -6,6 +6,9 @@ import registerCommands from "./functions/registerCommands.js";
|
||||||
|
|
||||||
export class CommandHandler {
|
export class CommandHandler {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
|
/**
|
||||||
|
* @type {import("../../structures/client.js").ExtendedClient} client
|
||||||
|
*/
|
||||||
this.client = client;
|
this.client = client;
|
||||||
this.commands = [];
|
this.commands = [];
|
||||||
}
|
}
|
||||||
|
@ -17,6 +20,8 @@ export class CommandHandler {
|
||||||
client: this.client,
|
client: this.client,
|
||||||
commands: this.commands,
|
commands: this.commands,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.handleCommands();
|
||||||
}
|
}
|
||||||
|
|
||||||
async #buildCommands() {
|
async #buildCommands() {
|
||||||
|
@ -39,4 +44,29 @@ export class CommandHandler {
|
||||||
this.commands.push({ data, run });
|
this.commands.push({ data, run });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleCommands() {
|
||||||
|
this.client.on("interactionCreate", async interaction => {
|
||||||
|
if (!interaction.isChatInputCommand() && !interaction.isAutocomplete()) return;
|
||||||
|
|
||||||
|
const isAutocomplete = interaction.isAutocomplete();
|
||||||
|
|
||||||
|
const targetCommand = this.commands.find(cmd => cmd.data.name === interaction.commandName);
|
||||||
|
|
||||||
|
if (!targetCommand) return;
|
||||||
|
// Skip if autocomplete handler is not defined
|
||||||
|
if (isAutocomplete && !targetCommand.autocompleteRun) return;
|
||||||
|
|
||||||
|
const command = targetCommand[isAutocomplete ? "autocompleteRun" : "run"];
|
||||||
|
|
||||||
|
try {
|
||||||
|
await command({
|
||||||
|
client: this.client,
|
||||||
|
interaction,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
logger.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue