aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-26 10:53:16 -0600
committerTymanWasTaken <32660892+tymanwastaken@users.noreply.github.com>2021-05-26 10:53:16 -0600
commit53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9 (patch)
tree15896b71e22fd7d1d002364c969bf14a00a29af0 /src/lib
parent9c345bf5f62eeb3f9f7246d8259e0978a18c7bc0 (diff)
downloadtanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.tar.gz
tanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.tar.bz2
tanzanite-53d8d5e551e9a239fd4c48c7dca4e1f6fb8d81e9.zip
pronouns command and use guild slash commands for testing not global
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/extensions/Util.ts23
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.}`
);
}
}