Skip to content

Commit

Permalink
fix(ApplicationCommandRegistries): registries are empty sometimes
Browse files Browse the repository at this point in the history
  • Loading branch information
vladfrangu authored and favna committed Feb 18, 2022
1 parent 9a25f47 commit 2358f2c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
18 changes: 3 additions & 15 deletions src/lib/structures/CommandStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AliasStore } from '@sapphire/pieces';
import { emitRegistryError } from '../utils/application-commands/emitRegistryError';
import { registries } from '../utils/application-commands/ApplicationCommandRegistries';
import { getNeededRegistryParameters } from '../utils/application-commands/getNeededParameters';
import { Command } from './Command';

Expand All @@ -21,16 +21,6 @@ export class CommandStore extends AliasStore<Command> {
return [...categories] as string[];
}

public override async insert(piece: Command) {
try {
await piece.registerApplicationCommands(piece.applicationCommandRegistry);
} catch (error) {
emitRegistryError(error, piece);
}

return super.insert(piece);
}

public override unload(name: string | Command) {
const piece = this.resolve(name);

Expand All @@ -49,10 +39,8 @@ export class CommandStore extends AliasStore<Command> {
}
}

// Reset the registry's contents
piece.applicationCommandRegistry.chatInputCommands.clear();
piece.applicationCommandRegistry.contextMenuCommands.clear();
piece.applicationCommandRegistry['apiCalls'].length = 0;
// Remove the registry from the application command registries
registries.delete(piece.name);

return super.unload(name);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { container } from '@sapphire/pieces';
import { RegisterBehavior } from '../../types/Enums';
import { ApplicationCommandRegistry } from './ApplicationCommandRegistry';
import { emitRegistryError } from './emitRegistryError';
import { getNeededRegistryParameters } from './getNeededParameters';

export let defaultBehaviorWhenNotIdentical = RegisterBehavior.LogToConsole;
Expand Down Expand Up @@ -40,6 +41,14 @@ export function getDefaultBehaviorWhenNotIdentical() {
export async function handleRegistryAPICalls() {
const commandStore = container.stores.get('commands');

for (const command of commandStore.values()) {
try {
await command.registerApplicationCommands(command.applicationCommandRegistry);
} catch (error) {
emitRegistryError(error, command);
}
}

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

for (const registry of registries.values()) {
Expand Down

0 comments on commit 2358f2c

Please sign in to comment.