From 53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9 Mon Sep 17 00:00:00 2001 From: TymanWasTaken <32660892+tymanwastaken@users.noreply.github.com> Date: Wed, 26 May 2021 10:53:16 -0600 Subject: pronouns command and use guild slash commands for testing not global --- src/lib/extensions/Util.ts | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/lib') 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 { + public async syncSlashCommands(force = false, guild?: string): Promise { + 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.}` ); } } -- cgit