@minesa-org/mini-interaction 0.0.1

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 (45) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/builders/ActionRowBuilder.d.ts +25 -0
  4. package/dist/builders/ActionRowBuilder.js +35 -0
  5. package/dist/builders/ButtonBuilder.d.ts +53 -0
  6. package/dist/builders/ButtonBuilder.js +124 -0
  7. package/dist/builders/ChannelSelectMenuBuilder.d.ts +58 -0
  8. package/dist/builders/ChannelSelectMenuBuilder.js +111 -0
  9. package/dist/builders/ModalBuilder.d.ts +40 -0
  10. package/dist/builders/ModalBuilder.js +65 -0
  11. package/dist/builders/RoleSelectMenuBuilder.d.ts +52 -0
  12. package/dist/builders/RoleSelectMenuBuilder.js +98 -0
  13. package/dist/builders/StringSelectMenuBuilder.d.ts +56 -0
  14. package/dist/builders/StringSelectMenuBuilder.js +100 -0
  15. package/dist/builders/index.d.ts +14 -0
  16. package/dist/builders/index.js +7 -0
  17. package/dist/builders/shared.d.ts +8 -0
  18. package/dist/builders/shared.js +11 -0
  19. package/dist/clients/MiniInteraction.d.ts +176 -0
  20. package/dist/clients/MiniInteraction.js +578 -0
  21. package/dist/commands/CommandBuilder.d.ts +278 -0
  22. package/dist/commands/CommandBuilder.js +687 -0
  23. package/dist/index.d.ts +16 -0
  24. package/dist/index.js +9 -0
  25. package/dist/types/ButtonStyle.d.ts +16 -0
  26. package/dist/types/ButtonStyle.js +17 -0
  27. package/dist/types/ChannelType.d.ts +2 -0
  28. package/dist/types/ChannelType.js +2 -0
  29. package/dist/types/Commands.d.ts +11 -0
  30. package/dist/types/Commands.js +1 -0
  31. package/dist/types/ComponentTypes.d.ts +5 -0
  32. package/dist/types/ComponentTypes.js +1 -0
  33. package/dist/types/InteractionFlags.d.ts +10 -0
  34. package/dist/types/InteractionFlags.js +12 -0
  35. package/dist/types/RoleConnectionMetadataTypes.d.ts +11 -0
  36. package/dist/types/RoleConnectionMetadataTypes.js +12 -0
  37. package/dist/utils/CommandInteractionOptions.d.ts +143 -0
  38. package/dist/utils/CommandInteractionOptions.js +376 -0
  39. package/dist/utils/MessageComponentInteraction.d.ts +19 -0
  40. package/dist/utils/MessageComponentInteraction.js +60 -0
  41. package/dist/utils/constants.d.ts +16 -0
  42. package/dist/utils/constants.js +16 -0
  43. package/dist/utils/interactionMessageHelpers.d.ts +30 -0
  44. package/dist/utils/interactionMessageHelpers.js +32 -0
  45. package/package.json +50 -0
@@ -0,0 +1,687 @@
1
+ import { ApplicationCommandOptionType, ApplicationCommandType, } from "discord-api-types/v10";
2
+ /** Maximum number of options allowed on a slash command or subcommand. */
3
+ const MAX_COMMAND_OPTIONS = 25;
4
+ /** Maximum number of choices allowed on choice-enabled options. */
5
+ const MAX_CHOICES = 25;
6
+ /** Maximum length of command or option names enforced by Discord. */
7
+ const MAX_NAME_LENGTH = 32;
8
+ /** Maximum description length permitted for commands and options. */
9
+ const MAX_DESCRIPTION_LENGTH = 100;
10
+ /** Maximum length of string option values supported by Discord. */
11
+ const MAX_STRING_LENGTH = 6000;
12
+ /** Minimum length of string option values. */
13
+ const MIN_STRING_LENGTH = 0;
14
+ /** Valid command and option name pattern as defined by Discord's API. */
15
+ const COMMAND_NAME_REGEX = /^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u;
16
+ /**
17
+ * Ensures an option or command name satisfies Discord's requirements.
18
+ */
19
+ function assertName(name, lowerCase = true) {
20
+ if (typeof name !== "string" || name.length === 0) {
21
+ throw new TypeError("Option name must be a non-empty string");
22
+ }
23
+ if (name.length > MAX_NAME_LENGTH || !COMMAND_NAME_REGEX.test(name)) {
24
+ throw new RangeError(`Option name "${name}" must match ${COMMAND_NAME_REGEX.source} and be at most ${MAX_NAME_LENGTH} characters long`);
25
+ }
26
+ if (lowerCase && name !== name.toLowerCase()) {
27
+ throw new RangeError(`Command and option names must be lowercase. Received "${name}"`);
28
+ }
29
+ }
30
+ /** Validates that a description string meets Discord's length constraints. */
31
+ function assertDescription(description) {
32
+ if (typeof description !== "string" || description.length === 0) {
33
+ throw new TypeError("Description must be a non-empty string");
34
+ }
35
+ if (description.length > MAX_DESCRIPTION_LENGTH) {
36
+ throw new RangeError(`Description must be between 1 and ${MAX_DESCRIPTION_LENGTH} characters long`);
37
+ }
38
+ }
39
+ /** Creates a deep copy of an option payload to avoid accidental mutation. */
40
+ function cloneOption(option) {
41
+ return JSON.parse(JSON.stringify(option));
42
+ }
43
+ /** Supported integration types for Discord application commands. */
44
+ export var IntegrationType;
45
+ (function (IntegrationType) {
46
+ IntegrationType[IntegrationType["GuildInstall"] = 0] = "GuildInstall";
47
+ IntegrationType[IntegrationType["UserInstall"] = 1] = "UserInstall";
48
+ })(IntegrationType || (IntegrationType = {}));
49
+ /** Supported contexts where a command can be invoked. */
50
+ export var CommandContext;
51
+ (function (CommandContext) {
52
+ CommandContext[CommandContext["Guild"] = 0] = "Guild";
53
+ CommandContext[CommandContext["Bot"] = 1] = "Bot";
54
+ CommandContext[CommandContext["DM"] = 2] = "DM";
55
+ })(CommandContext || (CommandContext = {}));
56
+ /**
57
+ * Provides shared builder utilities for application command option definitions.
58
+ */
59
+ class BaseOptionBuilder {
60
+ data;
61
+ /**
62
+ * Creates a new option builder wrapper around an underlying option payload.
63
+ */
64
+ constructor(data) {
65
+ this.data = data;
66
+ }
67
+ /**
68
+ * Sets the option name while validating Discord's requirements.
69
+ */
70
+ setName(name) {
71
+ assertName(name);
72
+ this.data.name = name;
73
+ return this;
74
+ }
75
+ /**
76
+ * Sets localized translations for the option name.
77
+ */
78
+ setNameLocalizations(localizations) {
79
+ this.data.name_localizations = localizations ?? null;
80
+ return this;
81
+ }
82
+ /**
83
+ * Sets the option description while validating Discord's length requirements.
84
+ */
85
+ setDescription(description) {
86
+ assertDescription(description);
87
+ this.data.description = description;
88
+ return this;
89
+ }
90
+ /**
91
+ * Sets localized translations for the option description.
92
+ */
93
+ setDescriptionLocalizations(localizations) {
94
+ this.data.description_localizations = localizations ?? null;
95
+ return this;
96
+ }
97
+ /**
98
+ * Produces a deep copy of the built option payload for safe reuse.
99
+ */
100
+ toJSON() {
101
+ return cloneOption(this.data);
102
+ }
103
+ }
104
+ /**
105
+ * Extends {@link BaseOptionBuilder} with helpers specific to basic command options.
106
+ */
107
+ class BaseCommandOptionBuilder extends BaseOptionBuilder {
108
+ /**
109
+ * Marks the option as required within its parent context.
110
+ */
111
+ setRequired(required = true) {
112
+ this.data.required = required;
113
+ return this;
114
+ }
115
+ }
116
+ /** Builder for attachment command options. */
117
+ class AttachmentOptionBuilder extends BaseCommandOptionBuilder {
118
+ constructor() {
119
+ super({
120
+ type: ApplicationCommandOptionType.Attachment,
121
+ name: "",
122
+ description: "",
123
+ });
124
+ }
125
+ }
126
+ /** Builder for user command options. */
127
+ class UserOptionBuilder extends BaseCommandOptionBuilder {
128
+ constructor() {
129
+ super({
130
+ type: ApplicationCommandOptionType.User,
131
+ name: "",
132
+ description: "",
133
+ });
134
+ }
135
+ }
136
+ /** Builder for role command options. */
137
+ class RoleOptionBuilder extends BaseCommandOptionBuilder {
138
+ constructor() {
139
+ super({
140
+ type: ApplicationCommandOptionType.Role,
141
+ name: "",
142
+ description: "",
143
+ });
144
+ }
145
+ }
146
+ /** Builder for mentionable command options. */
147
+ class MentionableOptionBuilder extends BaseCommandOptionBuilder {
148
+ constructor() {
149
+ super({
150
+ type: ApplicationCommandOptionType.Mentionable,
151
+ name: "",
152
+ description: "",
153
+ });
154
+ }
155
+ }
156
+ /** Builder for channel command options with channel type filtering support. */
157
+ class ChannelOptionBuilder extends BaseCommandOptionBuilder {
158
+ constructor() {
159
+ super({
160
+ type: ApplicationCommandOptionType.Channel,
161
+ name: "",
162
+ description: "",
163
+ });
164
+ }
165
+ /**
166
+ * Limits selectable channels to the provided channel types.
167
+ */
168
+ addChannelTypes(...channelTypes) {
169
+ if (channelTypes.length === 0) {
170
+ delete this.data.channel_types;
171
+ return this;
172
+ }
173
+ this.data.channel_types = [
174
+ ...channelTypes,
175
+ ];
176
+ return this;
177
+ }
178
+ }
179
+ /** Builder for string command options, including choice and autocomplete support. */
180
+ class StringOptionBuilder extends BaseCommandOptionBuilder {
181
+ constructor() {
182
+ super({
183
+ type: ApplicationCommandOptionType.String,
184
+ name: "",
185
+ description: "",
186
+ });
187
+ }
188
+ /**
189
+ * Adds a single choice option for the string command option.
190
+ */
191
+ addChoice(name, value) {
192
+ return this.addChoices({ name, value });
193
+ }
194
+ /**
195
+ * Adds multiple choice entries for the string command option.
196
+ */
197
+ addChoices(...choices) {
198
+ if (choices.length === 0) {
199
+ return this;
200
+ }
201
+ if (this.data.autocomplete) {
202
+ throw new Error("Cannot set choices when autocomplete is enabled");
203
+ }
204
+ this.data.choices ??= [];
205
+ if (this.data.choices.length + choices.length > MAX_CHOICES) {
206
+ throw new RangeError(`A maximum of ${MAX_CHOICES} choices can be set for an option`);
207
+ }
208
+ for (const choice of choices) {
209
+ assertName(choice.name, false);
210
+ this.data.choices.push({ ...choice });
211
+ }
212
+ return this;
213
+ }
214
+ /**
215
+ * Replaces the existing choice set with the provided entries.
216
+ */
217
+ setChoices(...choices) {
218
+ this.data.choices = [];
219
+ return this.addChoices(...choices);
220
+ }
221
+ /**
222
+ * Enables or disables autocomplete for the string option.
223
+ */
224
+ setAutocomplete(autocomplete = true) {
225
+ if (autocomplete && this.data.choices?.length) {
226
+ throw new Error("Cannot enable autocomplete when choices are already set");
227
+ }
228
+ this.data.autocomplete = autocomplete;
229
+ if (autocomplete) {
230
+ this.data.choices = [];
231
+ }
232
+ return this;
233
+ }
234
+ /**
235
+ * Sets the minimum string length accepted for the option value.
236
+ */
237
+ setMinLength(minLength) {
238
+ if (minLength < MIN_STRING_LENGTH || minLength > MAX_STRING_LENGTH) {
239
+ throw new RangeError(`minLength must be between ${MIN_STRING_LENGTH} and ${MAX_STRING_LENGTH}`);
240
+ }
241
+ this.data.min_length = minLength;
242
+ return this;
243
+ }
244
+ /**
245
+ * Sets the maximum string length accepted for the option value.
246
+ */
247
+ setMaxLength(maxLength) {
248
+ if (maxLength < 1 || maxLength > MAX_STRING_LENGTH) {
249
+ throw new RangeError(`maxLength must be between 1 and ${MAX_STRING_LENGTH}`);
250
+ }
251
+ this.data.max_length = maxLength;
252
+ return this;
253
+ }
254
+ }
255
+ /** Builder for numeric command options with choice and range support. */
256
+ class NumberOptionBuilder extends BaseCommandOptionBuilder {
257
+ constructor() {
258
+ super({
259
+ type: ApplicationCommandOptionType.Number,
260
+ name: "",
261
+ description: "",
262
+ });
263
+ }
264
+ /**
265
+ * Adds a single numeric choice for the option.
266
+ */
267
+ addChoice(name, value) {
268
+ return this.addChoices({ name, value });
269
+ }
270
+ /**
271
+ * Adds multiple numeric choice entries for the option.
272
+ */
273
+ addChoices(...choices) {
274
+ if (choices.length === 0) {
275
+ return this;
276
+ }
277
+ if (this.data.autocomplete) {
278
+ throw new Error("Cannot set choices when autocomplete is enabled");
279
+ }
280
+ this.data.choices ??= [];
281
+ if (this.data.choices.length + choices.length > MAX_CHOICES) {
282
+ throw new RangeError(`A maximum of ${MAX_CHOICES} choices can be set for an option`);
283
+ }
284
+ for (const choice of choices) {
285
+ assertName(choice.name, false);
286
+ this.data.choices.push({ ...choice });
287
+ }
288
+ return this;
289
+ }
290
+ /**
291
+ * Replaces the current choice set with the provided entries.
292
+ */
293
+ setChoices(...choices) {
294
+ this.data.choices = [];
295
+ return this.addChoices(...choices);
296
+ }
297
+ /**
298
+ * Enables or disables autocomplete for the numeric option.
299
+ */
300
+ setAutocomplete(autocomplete = true) {
301
+ if (autocomplete && this.data.choices?.length) {
302
+ throw new Error("Cannot enable autocomplete when choices are already set");
303
+ }
304
+ this.data.autocomplete = autocomplete;
305
+ if (autocomplete) {
306
+ this.data.choices = [];
307
+ }
308
+ return this;
309
+ }
310
+ /**
311
+ * Sets the minimum numeric value allowed for the option.
312
+ */
313
+ setMinValue(minValue) {
314
+ this.data.min_value = minValue;
315
+ return this;
316
+ }
317
+ /**
318
+ * Sets the maximum numeric value allowed for the option.
319
+ */
320
+ setMaxValue(maxValue) {
321
+ this.data.max_value = maxValue;
322
+ return this;
323
+ }
324
+ }
325
+ /**
326
+ * Resolves the JSON payload for a builder, allowing callback overrides to return custom builders.
327
+ */
328
+ function resolveBuilder(builder, callback) {
329
+ const result = callback?.(builder);
330
+ if (result && result !== builder) {
331
+ return result.toJSON();
332
+ }
333
+ return builder.toJSON();
334
+ }
335
+ /** Builder used to compose individual slash command subcommands. */
336
+ class SubcommandBuilder extends BaseOptionBuilder {
337
+ constructor() {
338
+ super({
339
+ type: ApplicationCommandOptionType.Subcommand,
340
+ name: "",
341
+ description: "",
342
+ options: [],
343
+ });
344
+ }
345
+ /**
346
+ * Ensures the subcommand does not exceed Discord's option limit.
347
+ */
348
+ assertOptionLimit(additional = 1) {
349
+ const current = this.data.options?.length ?? 0;
350
+ if (current + additional > MAX_COMMAND_OPTIONS) {
351
+ throw new RangeError(`A subcommand can only contain up to ${MAX_COMMAND_OPTIONS} options`);
352
+ }
353
+ }
354
+ /**
355
+ * Adds a string option configured through the supplied callback.
356
+ */
357
+ addStringOption(callback) {
358
+ this.assertOptionLimit();
359
+ const option = resolveBuilder(new StringOptionBuilder(), callback);
360
+ this.data.options?.push(option);
361
+ return this;
362
+ }
363
+ /**
364
+ * Adds a number option configured through the supplied callback.
365
+ */
366
+ addNumberOption(callback) {
367
+ this.assertOptionLimit();
368
+ const option = resolveBuilder(new NumberOptionBuilder(), callback);
369
+ this.data.options?.push(option);
370
+ return this;
371
+ }
372
+ /**
373
+ * Adds an attachment option configured through the supplied callback.
374
+ */
375
+ addAttachmentOption(callback) {
376
+ this.assertOptionLimit();
377
+ const option = resolveBuilder(new AttachmentOptionBuilder(), callback);
378
+ this.data.options?.push(option);
379
+ return this;
380
+ }
381
+ /**
382
+ * Adds a user option configured through the supplied callback.
383
+ */
384
+ addUserOption(callback) {
385
+ this.assertOptionLimit();
386
+ const option = resolveBuilder(new UserOptionBuilder(), callback);
387
+ this.data.options?.push(option);
388
+ return this;
389
+ }
390
+ /**
391
+ * Adds a role option configured through the supplied callback.
392
+ */
393
+ addRoleOption(callback) {
394
+ this.assertOptionLimit();
395
+ const option = resolveBuilder(new RoleOptionBuilder(), callback);
396
+ this.data.options?.push(option);
397
+ return this;
398
+ }
399
+ /**
400
+ * Adds a mentionable option configured through the supplied callback.
401
+ */
402
+ addMentionableOption(callback) {
403
+ this.assertOptionLimit();
404
+ const option = resolveBuilder(new MentionableOptionBuilder(), callback);
405
+ this.data.options?.push(option);
406
+ return this;
407
+ }
408
+ /**
409
+ * Adds a channel option configured through the supplied callback.
410
+ */
411
+ addChannelOption(callback) {
412
+ this.assertOptionLimit();
413
+ const option = resolveBuilder(new ChannelOptionBuilder(), callback);
414
+ this.data.options?.push(option);
415
+ return this;
416
+ }
417
+ /**
418
+ * Produces a serialisable representation of the subcommand configuration.
419
+ */
420
+ toJSON() {
421
+ return {
422
+ ...this.data,
423
+ options: this.data.options?.map((option) => cloneOption(option)) ?? [],
424
+ };
425
+ }
426
+ }
427
+ /** Builder used to compose groups of subcommands. */
428
+ class SubcommandGroupBuilder extends BaseOptionBuilder {
429
+ constructor() {
430
+ super({
431
+ type: ApplicationCommandOptionType.SubcommandGroup,
432
+ name: "",
433
+ description: "",
434
+ options: [],
435
+ });
436
+ }
437
+ /**
438
+ * Ensures the group does not exceed Discord's subcommand limit.
439
+ */
440
+ assertSubcommandLimit(additional = 1) {
441
+ const current = this.data.options?.length ?? 0;
442
+ if (current + additional > MAX_COMMAND_OPTIONS) {
443
+ throw new RangeError(`A subcommand group can only contain up to ${MAX_COMMAND_OPTIONS} subcommands`);
444
+ }
445
+ }
446
+ /**
447
+ * Adds a subcommand configured through the supplied callback.
448
+ */
449
+ addSubcommand(callback) {
450
+ this.assertSubcommandLimit();
451
+ const option = resolveBuilder(new SubcommandBuilder(), callback);
452
+ this.data.options?.push(option);
453
+ return this;
454
+ }
455
+ /**
456
+ * Produces a serialisable representation of the subcommand group configuration.
457
+ */
458
+ toJSON() {
459
+ return {
460
+ ...this.data,
461
+ options: this.data.options?.map((option) => cloneOption(option)) ?? [],
462
+ };
463
+ }
464
+ }
465
+ /** Fluent builder for constructing Discord chat input command payloads. */
466
+ export class CommandBuilder {
467
+ data = {
468
+ type: ApplicationCommandType.ChatInput,
469
+ };
470
+ /**
471
+ * Ensures the command does not exceed Discord's option limit.
472
+ */
473
+ assertOptionLimit(additional = 1) {
474
+ const current = this.data.options?.length ?? 0;
475
+ if (current + additional > MAX_COMMAND_OPTIONS) {
476
+ throw new RangeError(`A command can only contain up to ${MAX_COMMAND_OPTIONS} options`);
477
+ }
478
+ }
479
+ /**
480
+ * Sets the command name while validating Discord's requirements.
481
+ */
482
+ setName(name) {
483
+ assertName(name);
484
+ this.data.name = name;
485
+ return this;
486
+ }
487
+ /**
488
+ * Sets localized translations for the command name.
489
+ */
490
+ setNameLocalizations(localizations) {
491
+ this.data.name_localizations = localizations ?? null;
492
+ return this;
493
+ }
494
+ /**
495
+ * Sets the command description while enforcing Discord's length rules.
496
+ */
497
+ setDescription(description) {
498
+ assertDescription(description);
499
+ this.data.description = description;
500
+ return this;
501
+ }
502
+ /**
503
+ * Sets localized translations for the command description.
504
+ */
505
+ setDescriptionLocalizations(localizations) {
506
+ this.data.description_localizations = localizations ?? null;
507
+ return this;
508
+ }
509
+ /**
510
+ * Configures the default member permissions required to use the command.
511
+ */
512
+ setDefaultMemberPermissions(permissions) {
513
+ if (permissions === null) {
514
+ this.data.default_member_permissions = null;
515
+ return this;
516
+ }
517
+ if (typeof permissions === "bigint") {
518
+ this.data.default_member_permissions = permissions.toString();
519
+ return this;
520
+ }
521
+ if (typeof permissions === "number") {
522
+ this.data.default_member_permissions =
523
+ Math.floor(permissions).toString();
524
+ return this;
525
+ }
526
+ this.data.default_member_permissions = permissions;
527
+ return this;
528
+ }
529
+ /**
530
+ * Sets whether the command is available in direct messages.
531
+ */
532
+ setDMPermission(dmPermission) {
533
+ this.data.dm_permission = dmPermission;
534
+ return this;
535
+ }
536
+ /**
537
+ * Marks the command as not safe for work.
538
+ */
539
+ setNSFW(nsfw) {
540
+ this.data.nsfw = nsfw;
541
+ return this;
542
+ }
543
+ /**
544
+ * Limits the contexts in which the command can appear.
545
+ */
546
+ setContexts(contexts) {
547
+ this.data.contexts = contexts ? [...contexts] : null;
548
+ return this;
549
+ }
550
+ /**
551
+ * Specifies the integration types supported by the command.
552
+ */
553
+ setIntegrationTypes(integrationTypes) {
554
+ this.data.integration_types = [...integrationTypes];
555
+ return this;
556
+ }
557
+ /**
558
+ * Adds a subcommand to the command definition.
559
+ */
560
+ addSubcommand(callback) {
561
+ this.assertOptionLimit();
562
+ const option = resolveBuilder(new SubcommandBuilder(), callback);
563
+ this.data.options ??= [];
564
+ this.data.options.push(option);
565
+ return this;
566
+ }
567
+ /**
568
+ * Adds a subcommand group to the command definition.
569
+ */
570
+ addSubcommandGroup(callback) {
571
+ this.assertOptionLimit();
572
+ const option = resolveBuilder(new SubcommandGroupBuilder(), callback);
573
+ this.data.options ??= [];
574
+ this.data.options.push(option);
575
+ return this;
576
+ }
577
+ /**
578
+ * Adds a string option to the command definition.
579
+ */
580
+ addStringOption(callback) {
581
+ this.assertOptionLimit();
582
+ const option = resolveBuilder(new StringOptionBuilder(), callback);
583
+ this.data.options ??= [];
584
+ this.data.options.push(option);
585
+ return this;
586
+ }
587
+ /**
588
+ * Adds a number option to the command definition.
589
+ */
590
+ addNumberOption(callback) {
591
+ this.assertOptionLimit();
592
+ const option = resolveBuilder(new NumberOptionBuilder(), callback);
593
+ this.data.options ??= [];
594
+ this.data.options.push(option);
595
+ return this;
596
+ }
597
+ /**
598
+ * Adds an attachment option to the command definition.
599
+ */
600
+ addAttachmentOption(callback) {
601
+ this.assertOptionLimit();
602
+ const option = resolveBuilder(new AttachmentOptionBuilder(), callback);
603
+ this.data.options ??= [];
604
+ this.data.options.push(option);
605
+ return this;
606
+ }
607
+ /**
608
+ * Adds a user option to the command definition.
609
+ */
610
+ addUserOption(callback) {
611
+ this.assertOptionLimit();
612
+ const option = resolveBuilder(new UserOptionBuilder(), callback);
613
+ this.data.options ??= [];
614
+ this.data.options.push(option);
615
+ return this;
616
+ }
617
+ /**
618
+ * Adds a role option to the command definition.
619
+ */
620
+ addRoleOption(callback) {
621
+ this.assertOptionLimit();
622
+ const option = resolveBuilder(new RoleOptionBuilder(), callback);
623
+ this.data.options ??= [];
624
+ this.data.options.push(option);
625
+ return this;
626
+ }
627
+ /**
628
+ * Adds a mentionable option to the command definition.
629
+ */
630
+ addMentionableOption(callback) {
631
+ this.assertOptionLimit();
632
+ const option = resolveBuilder(new MentionableOptionBuilder(), callback);
633
+ this.data.options ??= [];
634
+ this.data.options.push(option);
635
+ return this;
636
+ }
637
+ /**
638
+ * Adds a channel option to the command definition.
639
+ */
640
+ addChannelOption(callback) {
641
+ this.assertOptionLimit();
642
+ const option = resolveBuilder(new ChannelOptionBuilder(), callback);
643
+ this.data.options ??= [];
644
+ this.data.options.push(option);
645
+ return this;
646
+ }
647
+ /**
648
+ * Produces the final REST payload for the configured command.
649
+ */
650
+ toJSON() {
651
+ const { name, description } = this.data;
652
+ if (!name) {
653
+ throw new Error("Command name has not been set");
654
+ }
655
+ if (!description) {
656
+ throw new Error("Command description has not been set");
657
+ }
658
+ const contexts = this.data.contexts;
659
+ const integrationTypes = this.data.integration_types;
660
+ return {
661
+ ...this.data,
662
+ name,
663
+ description,
664
+ contexts: contexts === null
665
+ ? null
666
+ : Array.isArray(contexts)
667
+ ? [...contexts]
668
+ : undefined,
669
+ integration_types: Array.isArray(integrationTypes)
670
+ ? [...integrationTypes]
671
+ : integrationTypes ?? undefined,
672
+ options: this.data.options?.map((option) => cloneOption(option)) ?? [],
673
+ };
674
+ }
675
+ /**
676
+ * Allows the builder to be coerced into its JSON payload automatically.
677
+ */
678
+ valueOf() {
679
+ return this.toJSON();
680
+ }
681
+ /**
682
+ * Formats the command as JSON when inspected in Node.js runtimes.
683
+ */
684
+ [Symbol.for("nodejs.util.inspect.custom")]() {
685
+ return this.toJSON();
686
+ }
687
+ }
@@ -0,0 +1,16 @@
1
+ /** Entry point re-exporting MiniInteraction helpers, builders, and shared types. */
2
+ export { MiniInteraction } from "./clients/MiniInteraction.js";
3
+ export type { RoleConnectionMetadataField } from "./clients/MiniInteraction.js";
4
+ export { CommandBuilder, CommandContext, IntegrationType, } from "./commands/CommandBuilder.js";
5
+ export type { AttachmentOptionBuilder, ChannelOptionBuilder, MentionableOptionBuilder, NumberOptionBuilder, RoleOptionBuilder, StringOptionBuilder, SubcommandBuilder, SubcommandGroupBuilder, UserOptionBuilder, } from "./commands/CommandBuilder.js";
6
+ export { CommandInteractionOptionResolver, createCommandInteraction, } from "./utils/CommandInteractionOptions.js";
7
+ export type { CommandInteraction, MentionableOption, ResolvedUserOption, } from "./utils/CommandInteractionOptions.js";
8
+ export type { MiniInteractionFetchHandler, MiniInteractionNodeHandler, MiniInteractionHandlerResult, MiniInteractionRequest, MiniInteractionOptions, } from "./clients/MiniInteraction.js";
9
+ export type { MiniInteractionCommand, SlashCommandHandler, } from "./types/Commands.js";
10
+ export type { MiniInteractionComponent, MiniInteractionComponentHandler, } from "./clients/MiniInteraction.js";
11
+ export { RoleConnectionMetadataTypes } from "./types/RoleConnectionMetadataTypes.js";
12
+ export { ChannelType } from "./types/ChannelType.js";
13
+ export { InteractionFollowUpFlags, InteractionReplyFlags, } from "./types/InteractionFlags.js";
14
+ export { ButtonStyle } from "./types/ButtonStyle.js";
15
+ export type { MiniComponentActionRow, MiniComponentMessageActionRow, } from "./types/ComponentTypes.js";
16
+ export * from "./builders/index.js";