@hyperneutrino/djs-lite 1.4.3 → 1.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.ts +6 -3
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -278,15 +278,18 @@ export async function loadInteractions(client: Client, directory: string, argume
|
|
|
278
278
|
|
|
279
279
|
export async function loadEvents(client: Client, directory: string, recursive: boolean = false) {
|
|
280
280
|
const handlers: Partial<{ [K in keyof ClientEvents]: ((...args: ClientEvents[K]) => unknown)[] }> = {};
|
|
281
|
+
const filenames: Partial<{ [K in keyof ClientEvents]: string[] }> = {};
|
|
281
282
|
|
|
282
283
|
await importAll({ directory, recursive }, async ({ relativePath, item }) => {
|
|
283
|
-
if (item instanceof EventHandler)
|
|
284
|
-
|
|
284
|
+
if (item instanceof EventHandler) {
|
|
285
|
+
(handlers[item.event as keyof ClientEvents] ??= []).push(item.handler);
|
|
286
|
+
(filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(directory, relativePath));
|
|
287
|
+
} else {
|
|
285
288
|
throw new Error(`Loading events failed: export from ${relativePath} was not an instance of EventHandler<T>.`);
|
|
286
289
|
}
|
|
287
290
|
});
|
|
288
291
|
|
|
289
292
|
Object.entries(handlers).forEach(([key, handlers]) => client.on(key, (...args) => handlers.forEach((handler) => (handler as any)(...args))));
|
|
290
293
|
|
|
291
|
-
return { handlers };
|
|
294
|
+
return { handlers, filenames };
|
|
292
295
|
}
|