diff options
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/extensions/Util.ts | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/lib/extensions/Util.ts b/src/lib/extensions/Util.ts index c99cb45..bd6823f 100644 --- a/src/lib/extensions/Util.ts +++ b/src/lib/extensions/Util.ts @@ -14,6 +14,7 @@ import { import { GuildChannel } from 'discord.js'; import { Role } from 'discord.js'; import chalk from 'chalk'; +import { Guild } from 'discord.js'; interface hastebinRes { key: string; @@ -244,9 +245,11 @@ export class Util extends ClientUtil { return apiRes.uuid.replace(/-/g, ''); } - public async syncSlashCommands(force = false): Promise<void> { + public async syncSlashCommands(force = false, guild?: string): Promise<void> { + let fetchedGuild: Guild + if (guild) fetchedGuild = this.client.guilds.cache.get(guild); try { - const registered = await this.client.application.commands.fetch(); + const registered = guild === undefined ? await this.client.application.commands.fetch() : await fetchedGuild.commands.fetch(); for (const [, registeredCommand] of registered) { if ( !this.client.commandHandler.modules.find( @@ -254,9 +257,9 @@ export class Util extends ClientUtil { )?.execSlash || force ) { - await this.client.application.commands.delete(registeredCommand.id); + guild === undefined ? await this.client.application.commands.delete(registeredCommand.id) : await fetchedGuild.commands.delete(registeredCommand.id); this.client.logger.verbose( - chalk`{red Deleted slash command ${registeredCommand.name}}` + chalk`{red Deleted slash command ${registeredCommand.name}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}` ); } } @@ -273,25 +276,25 @@ export class Util extends ClientUtil { if (found?.id && !force) { if (slashdata.description !== found.description) { - await this.client.application.commands.edit(found.id, slashdata); + guild === undefined ? await this.client.application.commands.edit(found.id, slashdata) : fetchedGuild.commands.edit(found.id, slashdata); this.client.logger.verbose( - chalk`{yellow Edited slash command ${botCommand.id}}` + chalk`{yellow Edited slash command ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}` ); } } else { - await this.client.application.commands.create(slashdata); + guild === undefined ? await this.client.application.commands.create(slashdata) : fetchedGuild.commands.create(slashdata); this.client.logger.verbose( - chalk`{green Created slash command ${botCommand.id}}` + chalk`{green Created slash command ${botCommand.id}${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}}` ); } } } - return this.client.logger.log(chalk.green('Slash commands registered')); + return this.client.logger.log(chalk.green(`Slash commands registered${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}`)); } catch (e) { console.log(chalk.red(e.stack)); return this.client.logger.error( - chalk`{red Slash commands not registered, see above error.}` + chalk`{red Slash commands not registered${guild !== undefined ? ` in guild ${fetchedGuild.name}`:''}, see above error.}` ); } } |