Skip to content

Commit

Permalink
fix: fire event 'ready' on modules (#50)
Browse files Browse the repository at this point in the history
Co-authored-by: Luca Montaigut <[email protected]>
Co-authored-by: Peïo Thibault <[email protected]>
  • Loading branch information
3 people authored Sep 4, 2023
1 parent b9854c9 commit 9221e88
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
8 changes: 3 additions & 5 deletions src/core/checkUniqueSlashCommandNames.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import type { BotModule } from '../types/bot';
import type { BotCommand } from '../types/bot';

export const checkUniqueSlashCommandNames = (modulesToLoad: Record<string, BotModule>) => {
const slashCommandNames = Object.values(modulesToLoad)
.flatMap((module) => module.slashCommands ?? [])
.map((command) => command.schema.name);
export const checkUniqueSlashCommandNames = (botCommands: BotCommand[]) => {
const slashCommandNames = botCommands.map((command) => command.schema.name);
const uniqueSlashCommandNames = new Set(slashCommandNames);
if (uniqueSlashCommandNames.size !== slashCommandNames.length) {
throw new Error('Found duplicate slash command names');
Expand Down
3 changes: 1 addition & 2 deletions src/core/loadModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ export const loadModules = async (
modulesToLoad: Record<string, BotModule>,
): Promise<void> => {
const botCommands = Object.values(modulesToLoad).flatMap((module) => module.slashCommands ?? []);

checkUniqueSlashCommandNames(modulesToLoad);
checkUniqueSlashCommandNames(botCommands);
routeCommands(client, botCommands);
await pushCommands(botCommands.map((command) => command.schema));

Expand Down
1 change: 1 addition & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const client = new Client({
await client.login(discord.token);
await new Promise<void>((resolve) => {
client.on('ready', () => {
Object.values(modules).map((module) => module.eventHandlers?.ready?.(client));
resolve();
});
});
Expand Down

0 comments on commit 9221e88

Please sign in to comment.