commandkit 0.1.11-dev.20250328085113 → 0.1.11-dev.20250330063035

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/dist/index.js CHANGED
@@ -176,8 +176,6 @@ var init_error_codes = __esm({
176
176
  "use strict";
177
177
  init_cjs_shims();
178
178
  CommandKitErrorCodes = {
179
- GuildOnlyException: Symbol("kGuildOnlyException"),
180
- DMOnlyException: Symbol("kDMOnlyException"),
181
179
  ExitMiddleware: Symbol("kExitMiddleware"),
182
180
  ForwardedCommand: Symbol("kForwardedCommand"),
183
181
  InvalidCommandPrefix: Symbol("kInvalidCommandPrefix"),
@@ -193,40 +191,19 @@ var init_error_codes = __esm({
193
191
  function exitContext(fn) {
194
192
  return context.exit(fn);
195
193
  }
194
+ function provideContext(value, receiver) {
195
+ return context.run(value, receiver);
196
+ }
196
197
  function makeContextAwareFunction(env, fn, finalizer) {
197
198
  const _fn = /* @__PURE__ */ __name((...args) => {
198
- return context.run(env, async () => {
199
+ return provideContext(env, async () => {
199
200
  try {
200
201
  const result = await fn(...args);
201
202
  return result;
202
203
  } catch (e) {
203
- if (isCommandKitError(e)) {
204
- const code = Reflect.get(e, "code");
205
- const interaction = env.variables.get("interaction");
206
- if (!interaction) return;
207
- switch (code) {
208
- case CommandKitErrorCodes.GuildOnlyException: {
209
- if (interaction.isRepliable()) {
210
- await interaction.reply({
211
- content: "This command is only available in guilds.",
212
- flags: import_discord2.MessageFlags.Ephemeral
213
- });
214
- }
215
- return;
216
- }
217
- case CommandKitErrorCodes.DMOnlyException: {
218
- if (interaction.isRepliable()) {
219
- await interaction.reply({
220
- content: "This command is only available in DMs.",
221
- flags: import_discord2.MessageFlags.Ephemeral
222
- });
223
- }
224
- return;
225
- }
226
- }
227
- return;
204
+ if (!isCommandKitError(e)) {
205
+ env.setExecutionError(e);
228
206
  }
229
- env.setExecutionError(e);
230
207
  } finally {
231
208
  if (typeof finalizer === "function") {
232
209
  try {
@@ -260,59 +237,33 @@ function useEnvironment() {
260
237
  }
261
238
  return ctx;
262
239
  }
263
- function guildOnly() {
264
- const env = useEnvironment();
265
- const interaction = env.variables.get("interaction");
266
- if (!interaction) {
267
- throw new Error("No interaction found in environment.");
268
- }
269
- if (!interaction.guild) {
270
- const error = new Error("This command is only available in guilds.");
271
- Reflect.set(error, "code", CommandKitErrorCodes.GuildOnlyException);
272
- throw error;
273
- }
274
- }
275
- function dmOnly() {
276
- const env = useEnvironment();
277
- const interaction = env.variables.get("interaction");
278
- if (!interaction) {
279
- throw new Error("No interaction found in environment.");
280
- }
281
- if (interaction.guild) {
282
- const error = new Error("This command is only available in DMs.");
283
- Reflect.set(error, "code", CommandKitErrorCodes.DMOnlyException);
284
- throw error;
285
- }
286
- }
287
- var import_node_async_hooks, import_discord2, context;
240
+ var import_node_async_hooks, context;
288
241
  var init_async_context = __esm({
289
242
  "src/context/async-context.ts"() {
290
243
  "use strict";
291
244
  init_cjs_shims();
292
245
  import_node_async_hooks = require("async_hooks");
293
- init_error_codes();
294
- import_discord2 = require("discord.js");
295
246
  init_CommandKit();
247
+ init_error_codes();
296
248
  context = new import_node_async_hooks.AsyncLocalStorage();
297
249
  __name(exitContext, "exitContext");
250
+ __name(provideContext, "provideContext");
298
251
  __name(makeContextAwareFunction, "makeContextAwareFunction");
299
252
  __name(getCommandKit, "getCommandKit");
300
253
  __name(getContext, "getContext");
301
254
  __name(useEnvironment, "useEnvironment");
302
- __name(guildOnly, "guildOnly");
303
- __name(dmOnly, "dmOnly");
304
255
  }
305
256
  });
306
257
 
307
258
  // src/components/button/ButtonKit.ts
308
- var import_discord3, _onClickHandler, _contextData, _unsub, _ButtonKit_instances, getEventInterceptor_fn, setupInteractionCollector_fn, destroyCollector_fn, _ButtonKit, ButtonKit;
259
+ var import_discord2, _onClickHandler, _contextData, _unsub, _ButtonKit_instances, getEventInterceptor_fn, setupInteractionCollector_fn, destroyCollector_fn, _ButtonKit, ButtonKit;
309
260
  var init_ButtonKit = __esm({
310
261
  "src/components/button/ButtonKit.ts"() {
311
262
  "use strict";
312
263
  init_cjs_shims();
313
- import_discord3 = require("discord.js");
264
+ import_discord2 = require("discord.js");
314
265
  init_async_context();
315
- _ButtonKit = class _ButtonKit extends import_discord3.ButtonBuilder {
266
+ _ButtonKit = class _ButtonKit extends import_discord2.ButtonBuilder {
316
267
  constructor() {
317
268
  super(...arguments);
318
269
  __privateAdd(this, _ButtonKit_instances);
@@ -351,7 +302,7 @@ var init_ButtonKit = __esm({
351
302
  */
352
303
  onClick(handler, data) {
353
304
  var _a, _b, _c, _d;
354
- if (this.data.style === import_discord3.ButtonStyle.Link) {
305
+ if (this.data.style === import_discord2.ButtonStyle.Link) {
355
306
  throw new TypeError('Cannot setup "onClick" handler on link buttons.');
356
307
  }
357
308
  if (!handler) {
@@ -375,7 +326,7 @@ var init_ButtonKit = __esm({
375
326
  return this;
376
327
  }
377
328
  onEnd(handler) {
378
- if (this.data.style === import_discord3.ButtonStyle.Link) {
329
+ if (this.data.style === import_discord2.ButtonStyle.Link) {
379
330
  throw new TypeError('Cannot setup "onEnd" handler on link buttons.');
380
331
  }
381
332
  if (!handler) {
@@ -432,7 +383,7 @@ var init_ButtonKit = __esm({
432
383
  return exitContext(() => ctx.commandkit.eventInterceptor);
433
384
  }, "#getEventInterceptor");
434
385
  setupInteractionCollector_fn = /* @__PURE__ */ __name(function() {
435
- if (this.data.style === import_discord3.ButtonStyle.Link || !__privateGet(this, _contextData) || !__privateGet(this, _onClickHandler))
386
+ if (this.data.style === import_discord2.ButtonStyle.Link || !__privateGet(this, _contextData) || !__privateGet(this, _onClickHandler))
436
387
  return;
437
388
  const myCustomId = this.customId ?? null;
438
389
  if (myCustomId === null) {
@@ -442,7 +393,7 @@ var init_ButtonKit = __esm({
442
393
  }
443
394
  const interceptor = __privateMethod(this, _ButtonKit_instances, getEventInterceptor_fn).call(this);
444
395
  __privateSet(this, _unsub, interceptor.subscribe(
445
- import_discord3.Events.InteractionCreate,
396
+ import_discord2.Events.InteractionCreate,
446
397
  async (interaction) => {
447
398
  var _a, _b;
448
399
  if (!interaction.isButton()) return;
@@ -473,7 +424,7 @@ var init_ButtonKit = __esm({
473
424
  // src/components/button/Button.ts
474
425
  function Button(props) {
475
426
  const button = new ButtonKit();
476
- props.style ??= import_discord4.ButtonStyle.Primary;
427
+ props.style ??= import_discord3.ButtonStyle.Primary;
477
428
  if (props.onClick) {
478
429
  props.customId ??= `buttonkit::${crypto.randomUUID()}`;
479
430
  }
@@ -512,26 +463,26 @@ function Button(props) {
512
463
  }
513
464
  return button;
514
465
  }
515
- var import_discord4;
466
+ var import_discord3;
516
467
  var init_Button = __esm({
517
468
  "src/components/button/Button.ts"() {
518
469
  "use strict";
519
470
  init_cjs_shims();
520
- import_discord4 = require("discord.js");
471
+ import_discord3 = require("discord.js");
521
472
  init_ButtonKit();
522
473
  __name(Button, "Button");
523
474
  }
524
475
  });
525
476
 
526
477
  // src/components/modal/ModalKit.ts
527
- var import_discord5, _onSubmitHandler, _contextData2, _unsub2, _ModalKit_instances, getEventInterceptor_fn2, setupCollector_fn, destroyCollector_fn2, _ModalKit, ModalKit;
478
+ var import_discord4, _onSubmitHandler, _contextData2, _unsub2, _ModalKit_instances, getEventInterceptor_fn2, setupCollector_fn, destroyCollector_fn2, _ModalKit, ModalKit;
528
479
  var init_ModalKit = __esm({
529
480
  "src/components/modal/ModalKit.ts"() {
530
481
  "use strict";
531
482
  init_cjs_shims();
532
- import_discord5 = require("discord.js");
483
+ import_discord4 = require("discord.js");
533
484
  init_async_context();
534
- _ModalKit = class _ModalKit extends import_discord5.ModalBuilder {
485
+ _ModalKit = class _ModalKit extends import_discord4.ModalBuilder {
535
486
  constructor() {
536
487
  super(...arguments);
537
488
  __privateAdd(this, _ModalKit_instances);
@@ -652,7 +603,7 @@ var init_ModalKit = __esm({
652
603
  const interceptor = __privateMethod(this, _ModalKit_instances, getEventInterceptor_fn2).call(this);
653
604
  if (!interceptor) return;
654
605
  __privateSet(this, _unsub2, interceptor.subscribe(
655
- import_discord5.Events.InteractionCreate,
606
+ import_discord4.Events.InteractionCreate,
656
607
  async (interaction) => {
657
608
  var _a, _b;
658
609
  if (!interaction.isModalSubmit()) return;
@@ -697,9 +648,9 @@ function Modal(props) {
697
648
  }
698
649
  if (props.children) {
699
650
  const childs = (Array.isArray(props.children) ? props.children : [props.children]).map((c) => {
700
- if (c instanceof import_discord6.ActionRowBuilder) return c;
701
- if (c instanceof import_discord6.TextInputBuilder)
702
- return new import_discord6.ActionRowBuilder().addComponents(c);
651
+ if (c instanceof import_discord5.ActionRowBuilder) return c;
652
+ if (c instanceof import_discord5.TextInputBuilder)
653
+ return new import_discord5.ActionRowBuilder().addComponents(c);
703
654
  }).filter((c) => c != null);
704
655
  modal.addComponents(childs);
705
656
  }
@@ -712,7 +663,7 @@ function Modal(props) {
712
663
  return modal;
713
664
  }
714
665
  function TextInput(props) {
715
- const input = new import_discord6.TextInputBuilder().setStyle(props.style);
666
+ const input = new import_discord5.TextInputBuilder().setStyle(props.style);
716
667
  if (props.customId) {
717
668
  input.setCustomId(props.customId);
718
669
  }
@@ -737,17 +688,17 @@ function TextInput(props) {
737
688
  return input;
738
689
  }
739
690
  function ShortInput(props) {
740
- return TextInput({ ...props, style: import_discord6.TextInputStyle.Short });
691
+ return TextInput({ ...props, style: import_discord5.TextInputStyle.Short });
741
692
  }
742
693
  function ParagraphInput(props) {
743
- return TextInput({ ...props, style: import_discord6.TextInputStyle.Paragraph });
694
+ return TextInput({ ...props, style: import_discord5.TextInputStyle.Paragraph });
744
695
  }
745
- var import_discord6;
696
+ var import_discord5;
746
697
  var init_Modal = __esm({
747
698
  "src/components/modal/Modal.ts"() {
748
699
  "use strict";
749
700
  init_cjs_shims();
750
- import_discord6 = require("discord.js");
701
+ import_discord5 = require("discord.js");
751
702
  init_ModalKit();
752
703
  __name(Modal, "Modal");
753
704
  __name(TextInput, "TextInput");
@@ -1128,12 +1079,6 @@ var init_RuntimePlugin = __esm({
1128
1079
  */
1129
1080
  async onBeforeInteraction(ctx, interaction) {
1130
1081
  }
1131
- /**
1132
- * Called after interaction is handled
1133
- * @param interaction The interaction that was handled
1134
- */
1135
- async onAfterInteraction(ctx, interaction) {
1136
- }
1137
1082
  /**
1138
1083
  * Called before message command is processed
1139
1084
  * @param message The message
@@ -1152,7 +1097,7 @@ var init_RuntimePlugin = __esm({
1152
1097
  * @param command The command
1153
1098
  * @param execute The function that executes the command
1154
1099
  */
1155
- async executeCommand(ctx, source, command, execute) {
1100
+ async executeCommand(ctx, env, source, command, execute) {
1156
1101
  return false;
1157
1102
  }
1158
1103
  };
@@ -1229,10 +1174,12 @@ var init_DefaultLogger = __esm({
1229
1174
  if (!kind && !commandHandler) return "";
1230
1175
  const h = execHandlerKind[kind];
1231
1176
  if (!h && !commandHandler) return "";
1232
- const t2 = commandHandler === "app" ? "(app \u2728) " : "";
1177
+ const forwardedBy = ctx.variables.get("forwardedBy");
1178
+ const forwardedTo = ctx.variables.get("forwardedTo");
1233
1179
  const cmdText = command ? colors_default.magenta(`/${command}`) + " " : "";
1180
+ const forward = forwardedTo ? `${colors_default.yellowBright(`(${forwardedBy || command} \u2192 ${forwardedTo})`)} ` : "";
1234
1181
  return colors_default.dim(`${BoxChars.vertical} `) + colors_default.cyanBright(
1235
- `${t2}${cmdText}${h ? colors_default.gray(`[${h}]`) : ""}`.trim()
1182
+ `${cmdText}${forward}${h ? colors_default.gray(`[${h}]`) : ""}`.trim()
1236
1183
  );
1237
1184
  }
1238
1185
  _getLevelLabel(level) {
@@ -1333,53 +1280,20 @@ var init_Logger = __esm({
1333
1280
  }
1334
1281
  });
1335
1282
 
1336
- // src/plugins/runtime/runtime-events/index.ts
1337
- var CommandKitPluginEvents, PluginEvents;
1338
- var init_runtime_events = __esm({
1339
- "src/plugins/runtime/runtime-events/index.ts"() {
1340
- "use strict";
1341
- init_cjs_shims();
1342
- CommandKitPluginEvents = {
1343
- "client-login": {
1344
- name: "ClientLogin",
1345
- cancelable: false
1346
- }
1347
- };
1348
- PluginEvents = Object.fromEntries(
1349
- Object.entries(CommandKitPluginEvents).map(
1350
- ([key, value]) => [
1351
- value.name,
1352
- class extends Event {
1353
- target;
1354
- constructor() {
1355
- super(key, { cancelable: value.cancelable });
1356
- }
1357
- }
1358
- ]
1359
- )
1360
- );
1361
- }
1362
- });
1363
-
1364
1283
  // src/plugins/runtime/CommandKitPluginRuntime.ts
1365
- var import_discord7, _CommandKitPluginRuntime, CommandKitPluginRuntime;
1284
+ var import_discord6, _CommandKitPluginRuntime, CommandKitPluginRuntime;
1366
1285
  var init_CommandKitPluginRuntime = __esm({
1367
1286
  "src/plugins/runtime/CommandKitPluginRuntime.ts"() {
1368
1287
  "use strict";
1369
1288
  init_cjs_shims();
1370
- import_discord7 = require("discord.js");
1289
+ import_discord6 = require("discord.js");
1371
1290
  init_error_codes();
1372
1291
  init_Logger();
1373
- init_runtime_events();
1374
- _CommandKitPluginRuntime = class _CommandKitPluginRuntime extends EventTarget {
1292
+ _CommandKitPluginRuntime = class _CommandKitPluginRuntime {
1375
1293
  constructor(commandkit2) {
1376
- super();
1377
1294
  this.commandkit = commandkit2;
1378
1295
  }
1379
- plugins = new import_discord7.Collection();
1380
- onClientLogin = /* @__PURE__ */ __name(() => {
1381
- this.dispatchEvent(new PluginEvents.ClientLogin());
1382
- }, "onClientLogin");
1296
+ plugins = new import_discord6.Collection();
1383
1297
  getPlugin(pluginName) {
1384
1298
  return this.plugins.get(pluginName) ?? null;
1385
1299
  }
@@ -2205,12 +2119,12 @@ var init_resolve_file_url = __esm({
2205
2119
  });
2206
2120
 
2207
2121
  // src/app/commands/MessageCommandParser.ts
2208
- var import_discord8, _parsed, _options, _args, _MessageCommandParser, MessageCommandParser, _MessageCommandOptions, MessageCommandOptions;
2122
+ var import_discord7, _parsed, _options, _args, _MessageCommandParser, MessageCommandParser, _MessageCommandOptions, MessageCommandOptions;
2209
2123
  var init_MessageCommandParser = __esm({
2210
2124
  "src/app/commands/MessageCommandParser.ts"() {
2211
2125
  "use strict";
2212
2126
  init_cjs_shims();
2213
- import_discord8 = require("discord.js");
2127
+ import_discord7 = require("discord.js");
2214
2128
  init_error_codes();
2215
2129
  _MessageCommandParser = class _MessageCommandParser {
2216
2130
  constructor(message, prefix, schema) {
@@ -2285,36 +2199,36 @@ var init_MessageCommandParser = __esm({
2285
2199
  const [name, value] = part.split(":");
2286
2200
  if (!(name in schema)) return null;
2287
2201
  switch (schema[name]) {
2288
- case import_discord8.ApplicationCommandOptionType.Boolean:
2202
+ case import_discord7.ApplicationCommandOptionType.Boolean:
2289
2203
  return { name, value: value === "true" };
2290
- case import_discord8.ApplicationCommandOptionType.Integer:
2204
+ case import_discord7.ApplicationCommandOptionType.Integer:
2291
2205
  return { name, value: parseInt(value, 10) };
2292
- case import_discord8.ApplicationCommandOptionType.Number:
2206
+ case import_discord7.ApplicationCommandOptionType.Number:
2293
2207
  return { name, value: parseFloat(value) };
2294
- case import_discord8.ApplicationCommandOptionType.String:
2208
+ case import_discord7.ApplicationCommandOptionType.String:
2295
2209
  return { name, value };
2296
- case import_discord8.ApplicationCommandOptionType.User:
2210
+ case import_discord7.ApplicationCommandOptionType.User:
2297
2211
  return {
2298
2212
  name,
2299
2213
  value: this.message.mentions.users.find((u) => {
2300
2214
  return u.id === value.replace(/[<@!>]/g, "");
2301
2215
  })
2302
2216
  };
2303
- case import_discord8.ApplicationCommandOptionType.Channel:
2217
+ case import_discord7.ApplicationCommandOptionType.Channel:
2304
2218
  return {
2305
2219
  name,
2306
2220
  value: this.message.mentions.channels.find((c) => {
2307
2221
  return c.id === value.replace(/[<#>]/g, "");
2308
2222
  })
2309
2223
  };
2310
- case import_discord8.ApplicationCommandOptionType.Role:
2224
+ case import_discord7.ApplicationCommandOptionType.Role:
2311
2225
  return {
2312
2226
  name,
2313
2227
  value: this.message.mentions.roles.find((r) => {
2314
2228
  return r.id === value.replace(/[<@&>]/g, "");
2315
2229
  })
2316
2230
  };
2317
- case import_discord8.ApplicationCommandOptionType.Attachment:
2231
+ case import_discord7.ApplicationCommandOptionType.Attachment:
2318
2232
  return {
2319
2233
  name,
2320
2234
  value: this.message.attachments.find((a) => {
@@ -2388,7 +2302,7 @@ var init_MessageCommandParser = __esm({
2388
2302
  }
2389
2303
  getMentionable(name, required = false) {
2390
2304
  const target = this.assertOption(name, required);
2391
- if (target instanceof import_discord8.GuildMember || target instanceof import_discord8.User || target instanceof import_discord8.Role) {
2305
+ if (target instanceof import_discord7.GuildMember || target instanceof import_discord7.User || target instanceof import_discord7.Role) {
2392
2306
  return target;
2393
2307
  }
2394
2308
  if (required) {
@@ -2417,12 +2331,12 @@ var init_MessageCommandParser = __esm({
2417
2331
  });
2418
2332
 
2419
2333
  // src/app/register/CommandRegistrar.ts
2420
- var import_discord9, _CommandRegistrar, CommandRegistrar;
2334
+ var import_discord8, _CommandRegistrar, CommandRegistrar;
2421
2335
  var init_CommandRegistrar = __esm({
2422
2336
  "src/app/register/CommandRegistrar.ts"() {
2423
2337
  "use strict";
2424
2338
  init_cjs_shims();
2425
- import_discord9 = require("discord.js");
2339
+ import_discord8 = require("discord.js");
2426
2340
  init_Logger();
2427
2341
  _CommandRegistrar = class _CommandRegistrar {
2428
2342
  /**
@@ -2435,7 +2349,7 @@ var init_CommandRegistrar = __esm({
2435
2349
  this.commandkit.client.token ?? process.env.DISCORD_TOKEN ?? process.env.TOKEN ?? ""
2436
2350
  );
2437
2351
  }
2438
- api = new import_discord9.REST();
2352
+ api = new import_discord8.REST();
2439
2353
  /**
2440
2354
  * Gets the commands data.
2441
2355
  */
@@ -2445,20 +2359,20 @@ var init_CommandRegistrar = __esm({
2445
2359
  return commands.flatMap((cmd) => {
2446
2360
  const json = "toJSON" in cmd.data.command ? cmd.data.command.toJSON() : cmd.data.command;
2447
2361
  const collections = [json];
2448
- if (cmd.data.userContextMenu && json.type !== import_discord9.ApplicationCommandType.User) {
2362
+ if (cmd.data.userContextMenu && json.type !== import_discord8.ApplicationCommandType.User) {
2449
2363
  collections.push({
2450
2364
  ...json,
2451
- type: import_discord9.ApplicationCommandType.User,
2365
+ type: import_discord8.ApplicationCommandType.User,
2452
2366
  options: void 0,
2453
2367
  description_localizations: void 0,
2454
2368
  // @ts-ignore
2455
2369
  description: void 0
2456
2370
  });
2457
2371
  }
2458
- if (cmd.data.messageContextMenu && json.type !== import_discord9.ApplicationCommandType.Message) {
2372
+ if (cmd.data.messageContextMenu && json.type !== import_discord8.ApplicationCommandType.Message) {
2459
2373
  collections.push({
2460
2374
  ...json,
2461
- type: import_discord9.ApplicationCommandType.Message,
2375
+ type: import_discord8.ApplicationCommandType.Message,
2462
2376
  description_localizations: void 0,
2463
2377
  // @ts-ignore
2464
2378
  description: void 0,
@@ -2502,7 +2416,7 @@ var init_CommandRegistrar = __esm({
2502
2416
  if (!commands.length) return;
2503
2417
  try {
2504
2418
  const data = await this.api.put(
2505
- import_discord9.Routes.applicationCommands(this.commandkit.client.user.id),
2419
+ import_discord8.Routes.applicationCommands(this.commandkit.client.user.id),
2506
2420
  {
2507
2421
  body: commands.map((c) => ({
2508
2422
  ...c,
@@ -2537,7 +2451,7 @@ var init_CommandRegistrar = __esm({
2537
2451
  let count = 0;
2538
2452
  for (const [guild, guildCommands] of guildCommandsMap) {
2539
2453
  const data = await this.api.put(
2540
- import_discord9.Routes.applicationGuildCommands(
2454
+ import_discord8.Routes.applicationGuildCommands(
2541
2455
  this.commandkit.client.user.id,
2542
2456
  guild
2543
2457
  ),
@@ -2697,7 +2611,9 @@ var init_environment = __esm({
2697
2611
  * @internal
2698
2612
  */
2699
2613
  markEnd() {
2700
- if (!__privateGet(this, _data).markEnd) __privateGet(this, _data).markEnd = performance.now();
2614
+ if (!__privateGet(this, _data).markEnd) {
2615
+ __privateGet(this, _data).markEnd = performance.now();
2616
+ }
2701
2617
  }
2702
2618
  /**
2703
2619
  * Get the marker.
@@ -3038,12 +2954,11 @@ var init_Context = __esm({
3038
2954
  */
3039
2955
  async forwardCommand(command) {
3040
2956
  const target = await this.commandkit.commandHandler.prepareCommandRun(
3041
- this.isInteraction() ? this.interaction : this.message
2957
+ this.isInteraction() ? this.interaction : this.message,
2958
+ command
3042
2959
  );
3043
2960
  if (!target) {
3044
- throw new Error(
3045
- `Command ${command} not found! If you are trying to forward to a legacy command, ctx.forwardCommand is not compatible with legacy commands.`
3046
- );
2961
+ throw new Error(`Command ${command} not found`);
3047
2962
  }
3048
2963
  const env = this.config.environment ?? getContext();
3049
2964
  if (!env) {
@@ -3066,6 +2981,8 @@ var init_Context = __esm({
3066
2981
  if (!handler) {
3067
2982
  throw new Error(`No handler found for ${handlerKind}`);
3068
2983
  }
2984
+ env.variables.set("forwardedBy", this.commandName);
2985
+ env.variables.set("forwardedTo", command);
3069
2986
  await handler(this.clone({ forwarded: true }));
3070
2987
  redirect();
3071
2988
  }
@@ -3271,23 +3188,24 @@ var init_Context = __esm({
3271
3188
  });
3272
3189
 
3273
3190
  // src/app/commands/AppCommandRunner.ts
3274
- var import_discord10, _AppCommandRunner_instances, finalizer_fn, _AppCommandRunner, AppCommandRunner;
3191
+ var import_discord9, _AppCommandRunner_instances, finalizer_fn, _AppCommandRunner, AppCommandRunner;
3275
3192
  var init_AppCommandRunner = __esm({
3276
3193
  "src/app/commands/AppCommandRunner.ts"() {
3277
3194
  "use strict";
3278
3195
  init_cjs_shims();
3279
- import_discord10 = require("discord.js");
3196
+ import_discord9 = require("discord.js");
3280
3197
  init_environment();
3281
3198
  init_Logger();
3282
3199
  init_Context();
3283
3200
  init_async_context();
3201
+ init_error_codes();
3284
3202
  _AppCommandRunner = class _AppCommandRunner {
3285
3203
  constructor(handler) {
3286
3204
  this.handler = handler;
3287
3205
  __privateAdd(this, _AppCommandRunner_instances);
3288
3206
  }
3289
3207
  async runCommand(prepared, source) {
3290
- if (source instanceof import_discord10.Message && (source.editedTimestamp || source.partial)) {
3208
+ if (source instanceof import_discord9.Message && (source.editedTimestamp || source.partial)) {
3291
3209
  return;
3292
3210
  }
3293
3211
  const { commandkit: commandkit2 } = this.handler;
@@ -3301,71 +3219,113 @@ var init_AppCommandRunner = __esm({
3301
3219
  const ctx = new MiddlewareContext(commandkit2, {
3302
3220
  environment: env,
3303
3221
  executionMode,
3304
- interaction: !(source instanceof import_discord10.Message) ? source : null,
3305
- message: source instanceof import_discord10.Message ? source : null,
3222
+ interaction: !(source instanceof import_discord9.Message) ? source : null,
3223
+ message: source instanceof import_discord9.Message ? source : null,
3306
3224
  forwarded: false,
3307
3225
  customArgs: {
3308
- setCommandRunner: /* @__PURE__ */ __name((fn2) => {
3309
- runCommand = fn2;
3226
+ setCommandRunner: /* @__PURE__ */ __name((fn) => {
3227
+ runCommand = fn;
3310
3228
  }, "setCommandRunner")
3311
3229
  },
3312
3230
  messageCommandParser: prepared.messageCommandParser
3313
3231
  });
3314
- for (const middleware of prepared.middlewares) {
3315
- await middleware.data.beforeExecute(ctx);
3316
- }
3317
- const targetData = prepared.command.data;
3318
- const fn = targetData[executionMode];
3319
- if (!fn) {
3320
- Logger.warn(
3321
- `Command ${prepared.command.command.name} has no handler for ${executionMode}`
3322
- );
3232
+ let middlewaresCanceled = false;
3233
+ if (prepared.middlewares.length) {
3234
+ await provideContext(env, async () => {
3235
+ for (const middleware of prepared.middlewares) {
3236
+ try {
3237
+ await middleware.data.beforeExecute(ctx);
3238
+ } catch (e) {
3239
+ if (isErrorType(e, CommandKitErrorCodes.ExitMiddleware)) {
3240
+ middlewaresCanceled = true;
3241
+ return;
3242
+ }
3243
+ if (isErrorType(
3244
+ e,
3245
+ [
3246
+ CommandKitErrorCodes.ForwardedCommand,
3247
+ CommandKitErrorCodes.InvalidCommandPrefix
3248
+ ]
3249
+ )) {
3250
+ continue;
3251
+ }
3252
+ throw e;
3253
+ }
3254
+ }
3255
+ });
3323
3256
  }
3324
- if (fn) {
3325
- try {
3326
- const _executeCommand = makeContextAwareFunction(
3327
- env,
3328
- async () => {
3329
- afterCommand((env2) => {
3330
- const error = env2.getExecutionError();
3331
- const marker = env2.getMarker();
3332
- const time = `${env2.getExecutionTime().toFixed(2)}ms`;
3333
- if (error) {
3334
- Logger.error(
3335
- `[${marker} - ${time}] Error executing command: ${error.stack || error}`
3336
- );
3337
- return;
3338
- }
3339
- Logger.info(
3340
- `[${marker} - ${time}] Command executed successfully`
3341
- );
3342
- });
3343
- return fn(ctx.clone());
3344
- },
3345
- __privateMethod(this, _AppCommandRunner_instances, finalizer_fn).bind(this)
3257
+ if (!ctx.cancelled) {
3258
+ const targetData = prepared.command.data;
3259
+ const fn = targetData[executionMode];
3260
+ if (!fn) {
3261
+ Logger.warn(
3262
+ `Command ${prepared.command.command.name} has no handler for ${executionMode}`
3346
3263
  );
3347
- const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
3348
- env.markStart(prepared.command.command.name);
3349
- const res = await commandkit2.plugins.execute(async (ctx2, plugin) => {
3350
- return plugin.executeCommand(ctx2, source, prepared, executeCommand);
3351
- });
3352
- if (!res) {
3353
- await executeCommand();
3264
+ }
3265
+ if (fn) {
3266
+ try {
3267
+ const _executeCommand = makeContextAwareFunction(
3268
+ env,
3269
+ async () => {
3270
+ env.registerDeferredFunction((env2) => {
3271
+ env2.markEnd();
3272
+ const error = env2.getExecutionError();
3273
+ const marker = env2.getMarker();
3274
+ const time = `${env2.getExecutionTime().toFixed(2)}ms`;
3275
+ if (error) {
3276
+ Logger.error(
3277
+ `[${marker} - ${time}] Error executing command: ${error.stack || error}`
3278
+ );
3279
+ return;
3280
+ }
3281
+ Logger.info(
3282
+ `[${marker} - ${time}] Command executed successfully`
3283
+ );
3284
+ });
3285
+ return fn(ctx.clone());
3286
+ },
3287
+ __privateMethod(this, _AppCommandRunner_instances, finalizer_fn).bind(this)
3288
+ );
3289
+ const executeCommand = runCommand != null ? runCommand(_executeCommand) : _executeCommand;
3290
+ env.markStart(prepared.command.data.command.name);
3291
+ const res = await commandkit2.plugins.execute(async (ctx2, plugin) => {
3292
+ return plugin.executeCommand(
3293
+ ctx2,
3294
+ env,
3295
+ source,
3296
+ prepared,
3297
+ executeCommand
3298
+ );
3299
+ });
3300
+ if (!res) {
3301
+ await executeCommand();
3302
+ }
3303
+ } catch (e) {
3304
+ if (isErrorType(e, CommandKitErrorCodes.ExitMiddleware)) {
3305
+ middlewaresCanceled = true;
3306
+ }
3307
+ if (!isErrorType(
3308
+ e,
3309
+ [
3310
+ CommandKitErrorCodes.ForwardedCommand,
3311
+ CommandKitErrorCodes.ExitMiddleware
3312
+ ]
3313
+ )) {
3314
+ Logger.error(e);
3315
+ }
3354
3316
  }
3355
- } catch (e) {
3356
- Logger.error(e);
3357
3317
  }
3358
3318
  }
3359
- try {
3360
- for (const middleware of prepared.middlewares) {
3361
- await middleware.data.afterExecute(ctx);
3362
- }
3363
- } finally {
3364
- env.markEnd();
3319
+ if (!middlewaresCanceled && prepared.middlewares.length) {
3320
+ await provideContext(env, async () => {
3321
+ for (const middleware of prepared.middlewares) {
3322
+ await middleware.data.afterExecute(ctx);
3323
+ }
3324
+ });
3365
3325
  }
3366
3326
  }
3367
3327
  getExecutionMode(source) {
3368
- if (source instanceof import_discord10.Message) return CommandExecutionMode.Message;
3328
+ if (source instanceof import_discord9.Message) return CommandExecutionMode.Message;
3369
3329
  if (source.isChatInputCommand()) return CommandExecutionMode.SlashCommand;
3370
3330
  if (source.isAutocomplete()) {
3371
3331
  return CommandExecutionMode.Autocomplete;
@@ -3463,12 +3423,12 @@ var init_types_package = __esm({
3463
3423
  });
3464
3424
 
3465
3425
  // src/app/handlers/AppCommandHandler.ts
3466
- var import_discord11, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
3426
+ var import_discord10, commandDataSchema, middlewareDataSchema, _AppCommandHandler, AppCommandHandler;
3467
3427
  var init_AppCommandHandler = __esm({
3468
3428
  "src/app/handlers/AppCommandHandler.ts"() {
3469
3429
  "use strict";
3470
3430
  init_cjs_shims();
3471
- import_discord11 = require("discord.js");
3431
+ import_discord10 = require("discord.js");
3472
3432
  init_resolve_file_url();
3473
3433
  init_MessageCommandParser();
3474
3434
  init_error_codes();
@@ -3478,7 +3438,7 @@ var init_AppCommandHandler = __esm({
3478
3438
  init_constants();
3479
3439
  init_types_package();
3480
3440
  commandDataSchema = {
3481
- command: /* @__PURE__ */ __name((c) => c instanceof import_discord11.SlashCommandBuilder || c instanceof import_discord11.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
3441
+ command: /* @__PURE__ */ __name((c) => c instanceof import_discord10.SlashCommandBuilder || c instanceof import_discord10.ContextMenuCommandBuilder || c && typeof c === "object", "command"),
3482
3442
  chatInput: /* @__PURE__ */ __name((c) => typeof c === "function", "chatInput"),
3483
3443
  autocomplete: /* @__PURE__ */ __name((c) => typeof c === "function", "autocomplete"),
3484
3444
  message: /* @__PURE__ */ __name((c) => typeof c === "function", "message"),
@@ -3494,8 +3454,8 @@ var init_AppCommandHandler = __esm({
3494
3454
  this.commandkit = commandkit2;
3495
3455
  this.registrar = new CommandRegistrar(this.commandkit);
3496
3456
  }
3497
- loadedCommands = new import_discord11.Collection();
3498
- loadedMiddlewares = new import_discord11.Collection();
3457
+ loadedCommands = new import_discord10.Collection();
3458
+ loadedMiddlewares = new import_discord10.Collection();
3499
3459
  // Name-to-ID mapping for easier lookup
3500
3460
  commandNameToId = /* @__PURE__ */ new Map();
3501
3461
  subcommandPathToId = /* @__PURE__ */ new Map();
@@ -3550,59 +3510,60 @@ var init_AppCommandHandler = __esm({
3550
3510
  if (!prepared) return;
3551
3511
  return this.commandRunner.runCommand(prepared, newMessage);
3552
3512
  };
3553
- this.commandkit.client.on(import_discord11.Events.InteractionCreate, this.onInteraction);
3554
- this.commandkit.client.on(import_discord11.Events.MessageCreate, this.onMessageCreate);
3555
- this.commandkit.client.on(import_discord11.Events.MessageUpdate, this.onMessageUpdate);
3513
+ this.commandkit.client.on(import_discord10.Events.InteractionCreate, this.onInteraction);
3514
+ this.commandkit.client.on(import_discord10.Events.MessageCreate, this.onMessageCreate);
3515
+ this.commandkit.client.on(import_discord10.Events.MessageUpdate, this.onMessageUpdate);
3556
3516
  }
3557
- async prepareCommandRun(source) {
3517
+ async prepareCommandRun(source, cmdName) {
3558
3518
  var _a;
3559
- let cmdName;
3560
3519
  let parser2;
3561
- if (source instanceof import_discord11.Message) {
3562
- if (source.author.bot) return null;
3563
- const prefix = await this.commandkit.config.getMessageCommandPrefix(source);
3564
- parser2 = new MessageCommandParser(
3565
- source,
3566
- Array.isArray(prefix) ? prefix : [prefix],
3567
- (command) => {
3568
- var _a2, _b;
3569
- const commandId2 = this.commandNameToId.get(command);
3570
- if (!commandId2) return null;
3571
- const loadedCommand2 = this.loadedCommands.get(commandId2);
3572
- if (!loadedCommand2) return null;
3573
- if (source.guildId && ((_a2 = loadedCommand2.guilds) == null ? void 0 : _a2.length) && !loadedCommand2.guilds.includes(source.guildId)) {
3520
+ if (!cmdName) {
3521
+ if (source instanceof import_discord10.Message) {
3522
+ if (source.author.bot) return null;
3523
+ const prefix = await this.commandkit.config.getMessageCommandPrefix(source);
3524
+ parser2 = new MessageCommandParser(
3525
+ source,
3526
+ Array.isArray(prefix) ? prefix : [prefix],
3527
+ (command) => {
3528
+ var _a2, _b;
3529
+ const commandId2 = this.commandNameToId.get(command);
3530
+ if (!commandId2) return null;
3531
+ const loadedCommand2 = this.loadedCommands.get(commandId2);
3532
+ if (!loadedCommand2) return null;
3533
+ if (source.guildId && ((_a2 = loadedCommand2.guilds) == null ? void 0 : _a2.length) && !loadedCommand2.guilds.includes(source.guildId)) {
3534
+ return null;
3535
+ }
3536
+ const json = "toJSON" in loadedCommand2.data.command ? loadedCommand2.data.command.toJSON() : loadedCommand2.data.command;
3537
+ return ((_b = json.options) == null ? void 0 : _b.reduce(
3538
+ (acc, opt) => {
3539
+ acc[opt.name] = opt.type;
3540
+ return acc;
3541
+ },
3542
+ {}
3543
+ )) ?? {};
3544
+ }
3545
+ );
3546
+ try {
3547
+ const fullCommand = parser2.getFullCommand();
3548
+ const parts = fullCommand.split(" ");
3549
+ cmdName = parts[0];
3550
+ } catch (e) {
3551
+ if (isErrorType(e, CommandKitErrorCodes.InvalidCommandPrefix)) {
3574
3552
  return null;
3575
3553
  }
3576
- const json = "toJSON" in loadedCommand2.data.command ? loadedCommand2.data.command.toJSON() : loadedCommand2.data.command;
3577
- return ((_b = json.options) == null ? void 0 : _b.reduce(
3578
- (acc, opt) => {
3579
- acc[opt.name] = opt.type;
3580
- return acc;
3581
- },
3582
- {}
3583
- )) ?? {};
3584
- }
3585
- );
3586
- try {
3587
- const fullCommand = parser2.getFullCommand();
3588
- const parts = fullCommand.split(" ");
3589
- cmdName = parts[0];
3590
- } catch (e) {
3591
- if (isErrorType(e, CommandKitErrorCodes.InvalidCommandPrefix)) {
3554
+ Logger.error(e);
3592
3555
  return null;
3593
3556
  }
3594
- Logger.error(e);
3595
- return null;
3557
+ } else {
3558
+ if (!source.isCommand()) return null;
3559
+ cmdName = source.commandName;
3596
3560
  }
3597
- } else {
3598
- if (!source.isCommand()) return null;
3599
- cmdName = source.commandName;
3600
3561
  }
3601
3562
  const commandId = this.commandNameToId.get(cmdName);
3602
3563
  if (!commandId) return null;
3603
3564
  const loadedCommand = this.loadedCommands.get(commandId);
3604
3565
  if (!loadedCommand) return null;
3605
- if (source instanceof import_discord11.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
3566
+ if (source instanceof import_discord10.CommandInteraction && source.guildId && ((_a = loadedCommand.guilds) == null ? void 0 : _a.length) && !loadedCommand.guilds.includes(source.guildId)) {
3606
3567
  return null;
3607
3568
  }
3608
3569
  const middlewares = [];
@@ -3721,7 +3682,7 @@ var init_AppCommandHandler = __esm({
3721
3682
  async applyLocalizations(command) {
3722
3683
  var _a, _b, _c, _d, _e;
3723
3684
  const localization = this.commandkit.config.localizationStrategy;
3724
- const validLocales = Object.values(import_discord11.Locale).filter(
3685
+ const validLocales = Object.values(import_discord10.Locale).filter(
3725
3686
  (v) => typeof v === "string"
3726
3687
  );
3727
3688
  const localizationKey = command.name;
@@ -3731,7 +3692,7 @@ var init_AppCommandHandler = __esm({
3731
3692
  locale
3732
3693
  );
3733
3694
  if (!(translation == null ? void 0 : translation.command)) continue;
3734
- if (command instanceof import_discord11.SlashCommandBuilder) {
3695
+ if (command instanceof import_discord10.SlashCommandBuilder) {
3735
3696
  if (translation.command.name) {
3736
3697
  command.setNameLocalization(locale, translation.command.name);
3737
3698
  }
@@ -3777,7 +3738,7 @@ var init_AppCommandHandler = __esm({
3777
3738
  });
3778
3739
  }
3779
3740
  }
3780
- } else if (command instanceof import_discord11.ContextMenuCommandBuilder) {
3741
+ } else if (command instanceof import_discord10.ContextMenuCommandBuilder) {
3781
3742
  if (translation.command.name) {
3782
3743
  command.setNameLocalization(locale, translation.command.name);
3783
3744
  }
@@ -3832,11 +3793,12 @@ var init_AppCommandHandler = __esm({
3832
3793
  });
3833
3794
 
3834
3795
  // src/app/router/CommandsRouter.ts
3835
- var import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
3796
+ var import_discord11, import_node_fs4, import_promises4, import_node_path4, MIDDLEWARE_PATTERN, COMMAND_PATTERN, CATEGORY_PATTERN, _CommandsRouter, CommandsRouter;
3836
3797
  var init_CommandsRouter = __esm({
3837
3798
  "src/app/router/CommandsRouter.ts"() {
3838
3799
  "use strict";
3839
3800
  init_cjs_shims();
3801
+ import_discord11 = require("discord.js");
3840
3802
  import_node_fs4 = require("fs");
3841
3803
  import_promises4 = require("fs/promises");
3842
3804
  import_node_path4 = require("path");
@@ -3847,8 +3809,8 @@ var init_CommandsRouter = __esm({
3847
3809
  constructor(options) {
3848
3810
  this.options = options;
3849
3811
  }
3850
- commands = /* @__PURE__ */ new Map();
3851
- middlewares = /* @__PURE__ */ new Map();
3812
+ commands = new import_discord11.Collection();
3813
+ middlewares = new import_discord11.Collection();
3852
3814
  populate(data) {
3853
3815
  for (const [id, command] of Object.entries(data.commands)) {
3854
3816
  this.commands.set(id, command);
@@ -3962,11 +3924,12 @@ var init_CommandsRouter = __esm({
3962
3924
  });
3963
3925
 
3964
3926
  // src/app/router/EventsRouter.ts
3965
- var import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
3927
+ var import_discord12, import_node_fs5, import_promises5, import_node_path5, _EventsRouter, EventsRouter;
3966
3928
  var init_EventsRouter = __esm({
3967
3929
  "src/app/router/EventsRouter.ts"() {
3968
3930
  "use strict";
3969
3931
  init_cjs_shims();
3932
+ import_discord12 = require("discord.js");
3970
3933
  import_node_fs5 = require("fs");
3971
3934
  import_promises5 = require("fs/promises");
3972
3935
  import_node_path5 = require("path");
@@ -3983,7 +3946,7 @@ var init_EventsRouter = __esm({
3983
3946
  }
3984
3947
  }
3985
3948
  /** Internal storage of parsed events */
3986
- events = /* @__PURE__ */ new Map();
3949
+ events = new import_discord12.Collection();
3987
3950
  /**
3988
3951
  * Find a parsed event by its name
3989
3952
  * @param event - Name of the event to find
@@ -4034,7 +3997,7 @@ var init_EventsRouter = __esm({
4034
3997
  return Object.fromEntries(this.events);
4035
3998
  }
4036
3999
  /**
4037
- * Convert the internal events map to a plain object
4000
+ * Convert the internal events Collection to a plain object
4038
4001
  * @returns Events tree as a plain object
4039
4002
  */
4040
4003
  toJSON() {
@@ -4426,7 +4389,7 @@ var init_CommandKitEventsChannel = __esm({
4426
4389
  });
4427
4390
 
4428
4391
  // src/CommandKit.ts
4429
- var import_node_events2, import_discord12, import_node_path8, import_node_fs8, commandkit, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
4392
+ var import_node_events2, import_discord13, import_node_path8, import_node_fs8, commandkit, _started, _CommandKit_instances, init_fn, initCommands_fn, initEvents_fn, _CommandKit, CommandKit;
4430
4393
  var init_CommandKit = __esm({
4431
4394
  "src/CommandKit.ts"() {
4432
4395
  "use strict";
@@ -4437,7 +4400,7 @@ var init_CommandKit = __esm({
4437
4400
  init_MemoryCache();
4438
4401
  init_components();
4439
4402
  init_EventInterceptor();
4440
- import_discord12 = require("discord.js");
4403
+ import_discord13 = require("discord.js");
4441
4404
  init_DefaultLocalizationStrategy();
4442
4405
  init_utilities();
4443
4406
  import_node_path8 = require("path");
@@ -4474,18 +4437,13 @@ var init_CommandKit = __esm({
4474
4437
  colors_default.red('"client" is required when instantiating CommandKit.')
4475
4438
  );
4476
4439
  }
4477
- if (options.validationsPath && !options.commandsPath) {
4478
- throw new Error(
4479
- colors_default.red('"commandsPath" is required when "validationsPath" is set.')
4480
- );
4481
- }
4482
4440
  super();
4483
4441
  this.options = options;
4484
4442
  __privateAdd(this, _CommandKit_instances);
4485
4443
  __privateAdd(this, _started, false);
4486
4444
  __publicField(this, "eventInterceptor");
4487
4445
  __publicField(this, "config", {
4488
- defaultLocale: import_discord12.Locale.EnglishUS,
4446
+ defaultLocale: import_discord13.Locale.EnglishUS,
4489
4447
  localizationStrategy: new DefaultLocalizationStrategy(this),
4490
4448
  getMessageCommandPrefix: /* @__PURE__ */ __name(() => "!", "getMessageCommandPrefix")
4491
4449
  });
@@ -4495,7 +4453,6 @@ var init_CommandKit = __esm({
4495
4453
  __publicField(this, "eventHandler", new AppEventsHandler(this));
4496
4454
  __publicField(this, "plugins");
4497
4455
  __publicField(this, "events", new CommandKitEventsChannel(this));
4498
- options.debugCommands ??= process.env.NODE_ENV !== "production";
4499
4456
  if (options.cacheProvider !== null && (!options.cacheProvider || !(options.cacheProvider instanceof CacheProvider))) {
4500
4457
  options.cacheProvider = new MemoryCache();
4501
4458
  }
@@ -4527,12 +4484,20 @@ var init_CommandKit = __esm({
4527
4484
  this.commandHandler.registerCommandHandler();
4528
4485
  this.incrementClientListenersCount();
4529
4486
  if (token !== false && !this.options.client.isReady()) {
4530
- this.client.once(import_discord12.Events.ClientReady, async () => {
4487
+ this.client.once(import_discord13.Events.ClientReady, async () => {
4531
4488
  await this.commandHandler.registrar.register();
4532
4489
  });
4490
+ await this.plugins.execute((ctx, plugin) => {
4491
+ var _a;
4492
+ return (_a = plugin.onBeforeClientLogin) == null ? void 0 : _a.call(plugin, ctx);
4493
+ });
4533
4494
  await this.options.client.login(
4534
4495
  token ?? process.env.TOKEN ?? process.env.DISCORD_TOKEN
4535
4496
  );
4497
+ await this.plugins.execute((ctx, plugin) => {
4498
+ var _a;
4499
+ return (_a = plugin.onAfterClientLogin) == null ? void 0 : _a.call(plugin, ctx);
4500
+ });
4536
4501
  } else if (this.options.client.isReady()) {
4537
4502
  await this.commandHandler.registrar.register();
4538
4503
  }
@@ -4586,12 +4551,6 @@ var init_CommandKit = __esm({
4586
4551
  const provider = this.options.cacheProvider;
4587
4552
  return provider ?? null;
4588
4553
  }
4589
- /**
4590
- * Whether or not to debug the command handler.
4591
- */
4592
- isDebuggingCommands() {
4593
- return this.options.debugCommands || false;
4594
- }
4595
4554
  /**
4596
4555
  * Get the client attached to this CommandKit instance.
4597
4556
  */
@@ -4610,42 +4569,6 @@ var init_CommandKit = __esm({
4610
4569
  async reloadEvents() {
4611
4570
  await this.eventHandler.reloadEvents();
4612
4571
  }
4613
- /**
4614
- * @returns The path to the commands folder which was set when instantiating CommandKit.
4615
- */
4616
- get commandsPath() {
4617
- return this.options.commandsPath;
4618
- }
4619
- /**
4620
- * @returns The path to the events folder which was set when instantiating CommandKit.
4621
- */
4622
- get eventsPath() {
4623
- return this.options.eventsPath;
4624
- }
4625
- /**
4626
- * @returns The path to the validations folder which was set when instantiating CommandKit.
4627
- */
4628
- get validationsPath() {
4629
- return this.options.validationsPath;
4630
- }
4631
- /**
4632
- * @returns An array of all the developer user IDs which was set when instantiating CommandKit.
4633
- */
4634
- get devUserIds() {
4635
- return this.options.devUserIds || [];
4636
- }
4637
- /**
4638
- * @returns An array of all the developer guild IDs which was set when instantiating CommandKit.
4639
- */
4640
- get devGuildIds() {
4641
- return this.options.devGuildIds || [];
4642
- }
4643
- /**
4644
- * @returns An array of all the developer role IDs which was set when instantiating CommandKit.
4645
- */
4646
- get devRoleIds() {
4647
- return this.options.devRoleIds || [];
4648
- }
4649
4572
  /**
4650
4573
  * Increment the client listeners count.
4651
4574
  */
@@ -4703,6 +4626,9 @@ var init_CommandKit = __esm({
4703
4626
  await __privateMethod(this, _CommandKit_instances, initCommands_fn).call(this);
4704
4627
  }, "#init");
4705
4628
  initCommands_fn = /* @__PURE__ */ __name(async function() {
4629
+ await this.plugins.execute((ctx, plugin) => {
4630
+ return plugin.onBeforeCommandsLoad(ctx);
4631
+ });
4706
4632
  if (this.commandsRouter.isValidPath()) {
4707
4633
  const result = await this.commandsRouter.scan();
4708
4634
  if (COMMANDKIT_IS_DEV) {
@@ -4713,12 +4639,21 @@ var init_CommandKit = __esm({
4713
4639
  }
4714
4640
  }
4715
4641
  await this.commandHandler.loadCommands();
4642
+ await this.plugins.execute((ctx, plugin) => {
4643
+ return plugin.onAfterCommandsLoad(ctx);
4644
+ });
4716
4645
  }, "#initCommands");
4717
4646
  initEvents_fn = /* @__PURE__ */ __name(async function() {
4647
+ await this.plugins.execute((ctx, plugin) => {
4648
+ return plugin.onBeforeEventsLoad(ctx);
4649
+ });
4718
4650
  if (this.eventsRouter.isValidPath()) {
4719
4651
  await this.eventsRouter.scan();
4720
4652
  }
4721
4653
  await this.eventHandler.loadEvents();
4654
+ await this.plugins.execute((ctx, plugin) => {
4655
+ return plugin.onAfterEventsLoad(ctx);
4656
+ });
4722
4657
  }, "#initEvents");
4723
4658
  __name(_CommandKit, "CommandKit");
4724
4659
  __publicField(_CommandKit, "createElement", createElement);
@@ -4739,7 +4674,7 @@ var init_version = __esm({
4739
4674
  "use strict";
4740
4675
  init_cjs_shims();
4741
4676
  version = /* @__MACRO__ $version */
4742
- "0.1.11-dev.20250328085113";
4677
+ "0.1.11-dev.20250330063035";
4743
4678
  }
4744
4679
  });
4745
4680
 
@@ -5218,7 +5153,7 @@ export default async function on${name[0].toUpperCase() + name.slice(1)}() {
5218
5153
  }
5219
5154
  async function generateLocale(locale, commandName, customPath) {
5220
5155
  const localeNames = Object.fromEntries(
5221
- Object.entries(import_discord13.Locale).map(([k, v]) => [v, k])
5156
+ Object.entries(import_discord15.Locale).map(([k, v]) => [v, k])
5222
5157
  );
5223
5158
  if (!localeNames[locale]) {
5224
5159
  panic(`Invalid locale: ${locale}`);
@@ -5250,14 +5185,14 @@ async function generateLocale(locale, commandName, customPath) {
5250
5185
  )
5251
5186
  );
5252
5187
  }
5253
- var import_promises7, import_path4, import_discord13, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
5188
+ var import_promises7, import_path4, import_discord15, import_fs2, BASE_PATH, COMMANDS_DIR, EVENTS_DIR, LOCALES_DIR, formatPath;
5254
5189
  var init_generators = __esm({
5255
5190
  "src/cli/generators.ts"() {
5256
5191
  "use strict";
5257
5192
  init_cjs_shims();
5258
5193
  import_promises7 = require("fs/promises");
5259
5194
  import_path4 = require("path");
5260
- import_discord13 = require("discord.js");
5195
+ import_discord15 = require("discord.js");
5261
5196
  init_common();
5262
5197
  import_fs2 = require("fs");
5263
5198
  init_colors();
@@ -5318,7 +5253,6 @@ __export(index_exports, {
5318
5253
  createLogger: () => createLogger,
5319
5254
  default: () => index_default,
5320
5255
  defineConfig: () => defineConfig,
5321
- dmOnly: () => dmOnly,
5322
5256
  exitContext: () => exitContext,
5323
5257
  exitMiddleware: () => exitMiddleware,
5324
5258
  fromEsbuildPlugin: () => fromEsbuildPlugin,
@@ -5326,13 +5260,15 @@ __export(index_exports, {
5326
5260
  getConfig: () => getConfig,
5327
5261
  getContext: () => getContext,
5328
5262
  getElement: () => getElement,
5329
- guildOnly: () => guildOnly,
5330
5263
  invalidate: () => invalidate,
5331
5264
  isCachedFunction: () => isCachedFunction,
5332
5265
  isCommandKitElement: () => isCommandKitElement,
5333
5266
  isCompilerPlugin: () => isCompilerPlugin,
5267
+ isInteractionSource: () => isInteractionSource,
5268
+ isMessageSource: () => isMessageSource,
5334
5269
  isRuntimePlugin: () => isRuntimePlugin,
5335
5270
  makeContextAwareFunction: () => makeContextAwareFunction,
5271
+ provideContext: () => provideContext,
5336
5272
  redirect: () => redirect,
5337
5273
  rethrow: () => rethrow,
5338
5274
  revalidate: () => revalidate,
@@ -5367,6 +5303,18 @@ init_cjs_shims();
5367
5303
  // src/app/index.ts
5368
5304
  init_signals();
5369
5305
 
5306
+ // src/app/commands/helpers.ts
5307
+ init_cjs_shims();
5308
+ var import_discord14 = require("discord.js");
5309
+ function isMessageSource(source) {
5310
+ return source instanceof import_discord14.Message;
5311
+ }
5312
+ __name(isMessageSource, "isMessageSource");
5313
+ function isInteractionSource(source) {
5314
+ return !isMessageSource(source);
5315
+ }
5316
+ __name(isInteractionSource, "isInteractionSource");
5317
+
5370
5318
  // src/index.ts
5371
5319
  init_DefaultLogger();
5372
5320
 
@@ -5485,7 +5433,6 @@ var index_default = CommandKit;
5485
5433
  createElement,
5486
5434
  createLogger,
5487
5435
  defineConfig,
5488
- dmOnly,
5489
5436
  exitContext,
5490
5437
  exitMiddleware,
5491
5438
  fromEsbuildPlugin,
@@ -5493,13 +5440,15 @@ var index_default = CommandKit;
5493
5440
  getConfig,
5494
5441
  getContext,
5495
5442
  getElement,
5496
- guildOnly,
5497
5443
  invalidate,
5498
5444
  isCachedFunction,
5499
5445
  isCommandKitElement,
5500
5446
  isCompilerPlugin,
5447
+ isInteractionSource,
5448
+ isMessageSource,
5501
5449
  isRuntimePlugin,
5502
5450
  makeContextAwareFunction,
5451
+ provideContext,
5503
5452
  redirect,
5504
5453
  rethrow,
5505
5454
  revalidate,