diff --git a/src/handler/events/interactionCreate.ts b/src/handler/events/interactionCreate.ts index 62193c0..70a778f 100644 --- a/src/handler/events/interactionCreate.ts +++ b/src/handler/events/interactionCreate.ts @@ -1,5 +1,5 @@ import type { Awaitable, ChatInputCommandInteraction, Interaction } from "discord.js"; -import { map, filter, fromEvent, Observable, of, mergeMap, tap} from "rxjs"; +import { map, filter, fromEvent, Observable, of, mergeMap, tap, concatMap} from "rxjs"; import { None, Some } from "ts-results"; import { CommandType } from "../sern"; import Context from "../structures/context"; @@ -13,7 +13,7 @@ export const onInteractionCreate = ( wrapper : Wrapper ) => { (fromEvent(client, 'interactionCreate') as Observable) .pipe( - mergeMap ( interaction => { + concatMap ( interaction => { if (interaction.isChatInputCommand()) { return of(interaction.commandName).pipe( map ( Files.Commands.get ), diff --git a/src/handler/structures/errors.ts b/src/handler/structures/errors.ts index 2b1a4db..92187e8 100644 --- a/src/handler/structures/errors.ts +++ b/src/handler/structures/errors.ts @@ -1,5 +1,6 @@ export enum SernError { RESERVED_EVENT = 'Cannot register the reserved ready event. Please use the init property.', NO_ALIAS = 'You cannot provide an array with elements to a slash command.', - NOT_VALID_MOD_TYPE = 'Detected an unknown module type' + NOT_VALID_MOD_TYPE = 'Detected an unknown module type', + UNDEFINED_MODULE = `A module could not be detected at` } diff --git a/src/handler/utilities/readFile.ts b/src/handler/utilities/readFile.ts index 00d2e3f..bd874ff 100644 --- a/src/handler/utilities/readFile.ts +++ b/src/handler/utilities/readFile.ts @@ -3,6 +3,7 @@ import type { ApplicationCommandOptionData } from 'discord.js'; import { readdirSync, statSync } from 'fs'; import { join } from 'path'; import type { Module } from '../structures/commands/module'; +import { SernError } from '../structures/errors'; export const Commands = new Map(); @@ -39,7 +40,9 @@ export async function buildData(commandDir: string ): Promise< > { return Promise.all( getCommands(commandDir).map( async (absPath) => { - return { mod: (await import(absPath)).module as Module, absPath }; + const mod = (await import(absPath)).module as Module; + if (mod === undefined) throw Error(`${SernError.UNDEFINED_MODULE} ${absPath}`) + return { mod, absPath }; }), ); }