Skip to content

Commit

Permalink
Merge branch 'master' into feat/quoi-feur
Browse files Browse the repository at this point in the history
  • Loading branch information
luca-montaigut committed Sep 4, 2023
2 parents 6b7d6b0 + 9221e88 commit d9cb95a
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 d9cb95a

Please sign in to comment.