@hyperneutrino/djs-lite 1.4.3 → 1.4.5

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.
Files changed (2) hide show
  1. package/index.ts +13 -7
  2. package/package.json +1 -1
package/index.ts CHANGED
@@ -185,7 +185,7 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
185
185
  };
186
186
  }
187
187
 
188
- export async function loadCommands(client: Client<true>, directory: string, guildId?: string) {
188
+ export async function loadCommands(client: Client<true>, directory: string, options?: { guildId?: string; skipSettingCommands?: boolean }) {
189
189
  const commandData: (ChatInputApplicationCommandData | UserApplicationCommandData | MessageApplicationCommandData)[] = [];
190
190
 
191
191
  const slashCommandHandlers = new Map<string, Handler<ChatInputCommandInteraction>>();
@@ -224,10 +224,13 @@ export async function loadCommands(client: Client<true>, directory: string, guil
224
224
  else if (interaction.isAutocomplete()) slashCommandAutocompletes.get(interaction.commandName)?.(interaction);
225
225
  });
226
226
 
227
- if (guildId) {
228
- const testGuild = client.guilds.resolve(guildId);
227
+ if (options?.skipSettingCommands) "Do nothing";
228
+ else if (options?.guildId) {
229
+ const testGuild = client.guilds.resolve(options.guildId);
229
230
  if (!testGuild)
230
- throw new Error(`Provided test guild (${guildId}) can not be found, please make sure the bot you started this project on is in this guild.`);
231
+ throw new Error(
232
+ `Provided test guild (${options.guildId}) can not be found, please make sure the bot you started this project on is in this guild.`,
233
+ );
231
234
  await testGuild.commands.set(commandData);
232
235
  } else {
233
236
  await client.application.commands.set(commandData);
@@ -278,15 +281,18 @@ export async function loadInteractions(client: Client, directory: string, argume
278
281
 
279
282
  export async function loadEvents(client: Client, directory: string, recursive: boolean = false) {
280
283
  const handlers: Partial<{ [K in keyof ClientEvents]: ((...args: ClientEvents[K]) => unknown)[] }> = {};
284
+ const filenames: Partial<{ [K in keyof ClientEvents]: string[] }> = {};
281
285
 
282
286
  await importAll({ directory, recursive }, async ({ relativePath, item }) => {
283
- if (item instanceof EventHandler) (handlers[item.event as keyof ClientEvents] ??= []).push(item.handler);
284
- else {
287
+ if (item instanceof EventHandler) {
288
+ (handlers[item.event as keyof ClientEvents] ??= []).push(item.handler);
289
+ (filenames[item.event as keyof ClientEvents] ??= []).push(path.relative(directory, relativePath));
290
+ } else {
285
291
  throw new Error(`Loading events failed: export from ${relativePath} was not an instance of EventHandler<T>.`);
286
292
  }
287
293
  });
288
294
 
289
295
  Object.entries(handlers).forEach(([key, handlers]) => client.on(key, (...args) => handlers.forEach((handler) => (handler as any)(...args))));
290
296
 
291
- return { handlers };
297
+ return { handlers, filenames };
292
298
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hyperneutrino/djs-lite",
3
3
  "private": false,
4
- "version": "1.4.3",
4
+ "version": "1.4.5",
5
5
  "module": "index.ts",
6
6
  "type": "module",
7
7
  "devDependencies": {