Skip to content

Commit

Permalink
feat: bulk overwrite applications commands (#210)
Browse files Browse the repository at this point in the history
* feat: bulk overwrite applications commands

That would purge all unlinded commands (no command file linked to a command)

fix #209

* feat: set default guild id for all commands

* fix: lint & formating errors
  • Loading branch information
WeeskyBDW authored and Romitou committed Jul 31, 2024
1 parent 41823e2 commit c45c026
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/structures/commands/SwanCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ApplicationCommandRegistry, ApplicationCommandRegistryRegisterOptions } from '@sapphire/framework';
import { Command, RegisterBehavior } from '@sapphire/framework';
import type { ApplicationCommandRegistry } from '@sapphire/framework';
import { ApplicationCommandRegistries, Command, RegisterBehavior } from '@sapphire/framework';
import type {
ApplicationCommandOptionData,
CacheType,
Expand All @@ -12,10 +12,8 @@ import type {
import { ApplicationCommandType, PermissionFlagsBits } from 'discord.js';
import type { SwanCommandOptions } from '#types/index';

const REGISTRY_OPTIONS: ApplicationCommandRegistryRegisterOptions = {
guildIds: [process.env.GUILD_ID],
behaviorWhenNotIdentical: RegisterBehavior.Overwrite,
};
ApplicationCommandRegistries.setDefaultBehaviorWhenNotIdentical(RegisterBehavior.BulkOverwrite);
ApplicationCommandRegistries.setDefaultGuildIds([process.env.GUILD_ID]);

export abstract class SwanCommand extends Command {
public command: string;
Expand Down Expand Up @@ -45,27 +43,21 @@ export abstract class SwanCommand extends Command {

switch (this.commandType) {
case ApplicationCommandType.ChatInput:
registry.registerChatInputCommand(
{
name: this.command,
description: this.description,
options: this.commandOptions,
dmPermission: this.dmPermission,
defaultMemberPermissions: this.defaultMemberPermissions,
},
REGISTRY_OPTIONS,
);
registry.registerChatInputCommand({
name: this.command,
description: this.description,
options: this.commandOptions,
dmPermission: this.dmPermission,
defaultMemberPermissions: this.defaultMemberPermissions,
});
break;

case ApplicationCommandType.User:
case ApplicationCommandType.Message:
registry.registerContextMenuCommand(
{
type: this.commandType,
name: this.command,
} as MessageApplicationCommandData | UserApplicationCommandData,
REGISTRY_OPTIONS,
);
registry.registerContextMenuCommand({
type: this.commandType,
name: this.command,
} as MessageApplicationCommandData | UserApplicationCommandData);
break;
}
}
Expand Down

0 comments on commit c45c026

Please sign in to comment.