Skip to content

Commit

Permalink
fix: reloading the entire command store didn't fire ApplicationComman…
Browse files Browse the repository at this point in the history
…dRegistries (#525)

* fix: reloading the entire command store didn't fire ApplicationCommandRegistries

* chore: smol fix

* chore: add note on current unload behavior for future changes

Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
  • Loading branch information
feefs and vladfrangu committed Oct 2, 2022
1 parent 7bebaf3 commit ad21eaa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/lib/structures/CommandStore.ts
@@ -1,5 +1,6 @@
import { AliasStore } from '@sapphire/pieces';
import { allGuildIdsToFetchCommandsFor, registries } from '../utils/application-commands/ApplicationCommandRegistries';
import { emitRegistryError } from '../utils/application-commands/emitRegistryError';
import { getNeededRegistryParameters } from '../utils/application-commands/getNeededParameters';
import { Command } from './Command';

Expand Down Expand Up @@ -51,6 +52,18 @@ export class CommandStore extends AliasStore<Command> {
// If we don't have an application, that means this was called on login...
if (!this.container.client.application) return;

// super.loadAll() currently deletes all application command registries while unloading old pieces,
// re-register application commands to ensure allGuildIdsToFetchCommandsFor has new guild ids for getNeededRegistryParameters
for (const command of this.values()) {
if (command.registerApplicationCommands) {
try {
await command.registerApplicationCommands(command.applicationCommandRegistry);
} catch (error) {
emitRegistryError(error, command);
}
}
}

const { applicationCommands, globalCommands, guildCommands } = await getNeededRegistryParameters(allGuildIdsToFetchCommandsFor);

for (const command of this.values()) {
Expand Down

0 comments on commit ad21eaa

Please sign in to comment.