Skip to content

Commit

Permalink
feat: add CommandManager#setCommands() and default impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Amgelo563 committed Sep 5, 2024
1 parent 4cfefd5 commit 78a7373
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/features/command/CommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,13 @@ export interface CommandManager extends BotAware, BotLifecycleObserver {
*/
editCommands(...commands: TopLevelCommand[]): Awaitable<this>;

/**
* Sets commands on Discord, or the pending ones if the bot hasn't started.
*
* @throws {Error} If the bot has already started, and there was an error while setting the commands.
*/
setCommands(...commands: TopLevelCommand[]): Awaitable<this>;

/**
* Subscribes a list of event subscribers to the manager's bus.
*
Expand Down
11 changes: 11 additions & 0 deletions packages/framework/src/features/command/DefaultCommandManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,17 @@ export class DefaultCommandManager implements CommandManager {
return this;
}

public async setCommands(...commands: TopLevelCommand[]): Promise<this> {
this.repository.clear();

for (const command of commands) {
this.repository.addCommand(command);
}

await this.deployer.setCommands(...commands);
return this;
}

public async autocomplete(
interaction: AutocompleteInteraction,
meta?: CommandExecutionMeta,
Expand Down

0 comments on commit 78a7373

Please sign in to comment.