@lunibee/builders 0.2.1 → 0.2.2

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/README.md CHANGED
@@ -8,31 +8,31 @@ bun add @lunibee/builders
8
8
 
9
9
  ```ts
10
10
  import {
11
- EmbedBuilder,
12
- ActionRowBuilder,
13
- ButtonBuilder,
14
- ButtonStyle,
15
- StringSelectMenuBuilder,
16
- SlashCommandBuilder,
11
+ CreateEmbed,
12
+ CreateActionRow,
13
+ CreateButton,
14
+ ButtonType,
15
+ CreateStringSelectMenu,
16
+ CreateSlashCommand,
17
17
  } from "@lunibee/builders";
18
18
 
19
- const embed = new EmbedBuilder()
19
+ const embed = new CreateEmbed()
20
20
  .setTitle("Welcome")
21
21
  .setDescription("Pick a role below.")
22
22
  .setColor(0xf5c542)
23
23
  .addFields([{ name: "Server", value: "Lunibee" }]);
24
24
 
25
- const buttons = new ActionRowBuilder().addComponents(
26
- new ButtonBuilder().setCustomId("yes").setLabel("Yes").setStyle(ButtonStyle.Success),
25
+ const buttons = new CreateActionRow().addComponents(
26
+ new CreateButton().setCustomId("yes").setLabel("Yes").setStyle(ButtonType.Success),
27
27
  );
28
28
 
29
- const menu = new ActionRowBuilder().addComponents(
30
- new StringSelectMenuBuilder()
29
+ const menu = new CreateActionRow().addComponents(
30
+ new CreateStringSelectMenu()
31
31
  .setCustomId("role")
32
32
  .addOptions({ label: "Developer", value: "dev" }),
33
33
  );
34
34
 
35
- const ping = new SlashCommandBuilder()
35
+ const ping = new CreateSlashCommand()
36
36
  .setName("ping")
37
37
  .setDescription("Replies with pong")
38
38
  .addStringOption((option) => option.setName("message").setDescription("Echo text"));
@@ -44,26 +44,26 @@ console.log(embed.toJSON(), buttons.toJSON(), menu.toJSON(), ping.toJSON());
44
44
 
45
45
  | Area | Builders |
46
46
  |---|---|
47
- | Embeds | `EmbedBuilder` |
48
- | Buttons & rows | `ButtonBuilder`, `ActionRowBuilder` |
49
- | Select menus | `StringSelectBuilder` (alias `StringSelectMenuBuilder`), `EntitySelectBuilder`, `UserSelectMenuBuilder`, `RoleSelectMenuBuilder`, `ChannelSelectMenuBuilder`, `MentionableSelectMenuBuilder` |
50
- | Modals | `ModalBuilder`, `TextInputBuilder` |
51
- | Slash commands | `SlashCommandBuilder`, `SubcommandBuilder`, `SubcommandGroupBuilder`, option builders |
52
- | Context menus | `ContextMenuCommandBuilder` (`setType(2 \| 3)`), `UserCommandBuilder`, `MessageCommandBuilder` |
53
- | Components V2 | `ContainerBuilder`, `SectionBuilder`, `TextDisplayBuilder`, `MediaGalleryBuilder`, `FileComponentBuilder`, `SeparatorBuilder`, `ThumbnailBuilder` |
54
- | Files | `AttachmentBuilder` |
47
+ | Embeds | `CreateEmbed` |
48
+ | Buttons & rows | `CreateButton`, `CreateActionRow` |
49
+ | Select menus | `CreateStringSelect` (alias `CreateStringSelectMenu`), `CreateEntitySelect`, `CreateUserSelectMenu`, `CreateRoleSelectMenu`, `CreateChannelSelectMenu`, `CreateMentionableSelectMenu` |
50
+ | Modals | `CreateModal`, `CreateTextInput` |
51
+ | Slash commands | `CreateSlashCommand`, `CreateSubcommand`, `CreateSubcommandGroup`, option builders |
52
+ | Context menus | `CreateContextMenuCommand` (`setType(2 \| 3)`), `CreateUserCommand`, `CreateMessageCommand` |
53
+ | Components V2 | `CreateContainer`, `CreateSection`, `CreateTextDisplay`, `CreateMediaGallery`, `CreateFileComponent`, `CreateSeparator`, `CreateThumbnail` |
54
+ | Files | `CreateAttachment` |
55
55
 
56
56
  Every builder validates Discord's limits as you set values and serialises with `toJSON()`.
57
57
 
58
58
  ## What's new in 0.2.1
59
59
 
60
- - `ModalBuilder.addTextInputs(...inputs)` wraps each text input in its own row.
60
+ - `CreateModal.addTextInputs(...inputs)` wraps each text input in its own row.
61
61
  - `componentsV2Message(components, options?)` builds a Components V2 message with the required flag.
62
- - `EmbedBuilder` setters (`setTitle`, `setDescription`, `setURL`, `setThumbnail`, `setImage`) clear the field with `null`.
63
- - `TextInputStyle` and `ComponentType` are usable as types; `ModalBuilder.toJSON()` is typed with a required `custom_id` and `title`.
62
+ - `CreateEmbed` setters (`setTitle`, `setDescription`, `setURL`, `setThumbnail`, `setImage`) clear the field with `null`.
63
+ - `TextInputType` and `ComponentEnum` are usable as types; `CreateModal.toJSON()` is typed with a required `custom_id` and `title`.
64
64
 
65
65
  ## What's new in 0.2.0
66
66
 
67
- `toJSON()` validates whole components (required fields, value bounds, action-row rules, button field exclusivity); `ButtonBuilder.setSKUId()` for premium buttons.
67
+ `toJSON()` validates whole components (required fields, value bounds, action-row rules, button field exclusivity); `CreateButton.setSKUId()` for premium buttons.
68
68
 
69
69
  Docs: https://lunibee.js.org/core-concepts/builders/
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lunibee/builders",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "type": "module",
5
5
  "module": "./src/index.ts",
6
6
  "types": "./src/index.ts",
package/src/attachment.ts CHANGED
@@ -8,7 +8,7 @@ export interface AttachmentData {
8
8
  }
9
9
 
10
10
  /** Builder for message attachments and file uploads. */
11
- export class AttachmentBuilder {
11
+ export class CreateAttachment {
12
12
  public name: string;
13
13
  public description?: string;
14
14
  public file: Uint8Array | ArrayBuffer | Blob | Buffer | string;
@@ -68,3 +68,12 @@ export class AttachmentBuilder {
68
68
  );
69
69
  }
70
70
  }
71
+
72
+ // ─── Deprecated names (0.2.2), removed in 2.0 ────────────────────────────────
73
+ // Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
74
+ // `…Type` and `…Type` became `…Enum`.
75
+
76
+ /** @deprecated Use {@link CreateAttachment}. Removed in 2.0. */
77
+ export const AttachmentBuilder = CreateAttachment;
78
+ /** @deprecated Use {@link CreateAttachment}. Removed in 2.0. */
79
+ export type AttachmentBuilder = CreateAttachment;
package/src/commands.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /** Discord application command option types. */
2
- export const ApplicationCommandOptionType = {
2
+ export const ApplicationCommandOptionEnum = {
3
3
  Subcommand: 1,
4
4
  SubcommandGroup: 2,
5
5
  String: 3,
@@ -12,9 +12,12 @@ export const ApplicationCommandOptionType = {
12
12
  Number: 10,
13
13
  Attachment: 11,
14
14
  } as const;
15
+ /** One {@link ApplicationCommandOptionEnum} value, usable as a type. */
16
+ export type ApplicationCommandOptionEnum =
17
+ (typeof ApplicationCommandOptionEnum)[keyof typeof ApplicationCommandOptionEnum];
15
18
 
16
19
  /** Builds Discord application command payloads. */
17
- export class SlashCommandBuilder {
20
+ export class CreateSlashCommand {
18
21
  readonly #data: Record<string, unknown> = { type: 1 };
19
22
  /** Sets the command name. */ public setName(name: string): this {
20
23
  validateName(name, "Command name");
@@ -57,61 +60,59 @@ export class SlashCommandBuilder {
57
60
  return this;
58
61
  }
59
62
  /** Adds a string option. */ public addStringOption(
60
- configure: (option: StringOptionBuilder) => StringOptionBuilder,
63
+ configure: (option: CreateStringOption) => CreateStringOption,
61
64
  ): this {
62
- return this.addOption(configure(new StringOptionBuilder()));
65
+ return this.addOption(configure(new CreateStringOption()));
63
66
  }
64
67
  /** Adds an integer option. */ public addIntegerOption(
65
- configure: (option: IntegerOptionBuilder) => IntegerOptionBuilder,
68
+ configure: (option: CreateIntegerOption) => CreateIntegerOption,
66
69
  ): this {
67
- return this.addOption(configure(new IntegerOptionBuilder()));
70
+ return this.addOption(configure(new CreateIntegerOption()));
68
71
  }
69
72
  /** Adds a number option. */ public addNumberOption(
70
- configure: (option: NumberOptionBuilder) => NumberOptionBuilder,
73
+ configure: (option: CreateNumberOption) => CreateNumberOption,
71
74
  ): this {
72
- return this.addOption(configure(new NumberOptionBuilder()));
75
+ return this.addOption(configure(new CreateNumberOption()));
73
76
  }
74
77
  /** Adds a boolean option. */ public addBooleanOption(
75
- configure: (option: BooleanOptionBuilder) => BooleanOptionBuilder,
78
+ configure: (option: CreateBooleanOption) => CreateBooleanOption,
76
79
  ): this {
77
- return this.addOption(configure(new BooleanOptionBuilder()));
80
+ return this.addOption(configure(new CreateBooleanOption()));
78
81
  }
79
82
  /** Adds a user option. */ public addUserOption(
80
- configure: (option: UserOptionBuilder) => UserOptionBuilder,
83
+ configure: (option: CreateUserOption) => CreateUserOption,
81
84
  ): this {
82
- return this.addOption(configure(new UserOptionBuilder()));
85
+ return this.addOption(configure(new CreateUserOption()));
83
86
  }
84
87
  /** Adds a channel option. */ public addChannelOption(
85
- configure: (option: ChannelOptionBuilder) => ChannelOptionBuilder,
88
+ configure: (option: CreateChannelOption) => CreateChannelOption,
86
89
  ): this {
87
- return this.addOption(configure(new ChannelOptionBuilder()));
90
+ return this.addOption(configure(new CreateChannelOption()));
88
91
  }
89
92
  /** Adds a role option. */ public addRoleOption(
90
- configure: (option: RoleOptionBuilder) => RoleOptionBuilder,
93
+ configure: (option: CreateRoleOption) => CreateRoleOption,
91
94
  ): this {
92
- return this.addOption(configure(new RoleOptionBuilder()));
95
+ return this.addOption(configure(new CreateRoleOption()));
93
96
  }
94
97
  /** Adds a mentionable option. */ public addMentionableOption(
95
- configure: (
96
- option: MentionableOptionBuilder,
97
- ) => MentionableOptionBuilder,
98
+ configure: (option: CreateMentionableOption) => CreateMentionableOption,
98
99
  ): this {
99
- return this.addOption(configure(new MentionableOptionBuilder()));
100
+ return this.addOption(configure(new CreateMentionableOption()));
100
101
  }
101
102
  /** Adds an attachment option. */ public addAttachmentOption(
102
- configure: (option: AttachmentOptionBuilder) => AttachmentOptionBuilder,
103
+ configure: (option: CreateAttachmentOption) => CreateAttachmentOption,
103
104
  ): this {
104
- return this.addOption(configure(new AttachmentOptionBuilder()));
105
+ return this.addOption(configure(new CreateAttachmentOption()));
105
106
  }
106
107
  /** Adds a subcommand. */ public addSubcommand(
107
- configure: (option: SubcommandBuilder) => SubcommandBuilder,
108
+ configure: (option: CreateSubcommand) => CreateSubcommand,
108
109
  ): this {
109
- return this.addOption(configure(new SubcommandBuilder()));
110
+ return this.addOption(configure(new CreateSubcommand()));
110
111
  }
111
112
  /** Adds a subcommand group. */ public addSubcommandGroup(
112
- configure: (option: SubcommandGroupBuilder) => SubcommandGroupBuilder,
113
+ configure: (option: CreateSubcommandGroup) => CreateSubcommandGroup,
113
114
  ): this {
114
- return this.addOption(configure(new SubcommandGroupBuilder()));
115
+ return this.addOption(configure(new CreateSubcommandGroup()));
115
116
  }
116
117
  /** Serializes the command payload. */ public toJSON(): Record<
117
118
  string,
@@ -120,7 +121,7 @@ export class SlashCommandBuilder {
120
121
  return structuredClone(this.#data);
121
122
  }
122
123
  /** Adds a validated top-level command option. */ protected addOption(
123
- option: CommandOptionBuilder,
124
+ option: CreateCommandOption,
124
125
  ): this {
125
126
  const options = (this.#data.options as unknown[] | undefined) ?? [];
126
127
  if (options.length >= 25)
@@ -154,7 +155,7 @@ export class SlashCommandBuilder {
154
155
  }
155
156
 
156
157
  /** Base builder for command options. */
157
- export class CommandOptionBuilder {
158
+ export class CreateCommandOption {
158
159
  protected readonly data: Record<string, unknown>;
159
160
  /** Creates an option builder. */ public constructor(type: number) {
160
161
  this.data = { type };
@@ -190,9 +191,9 @@ export class CommandOptionBuilder {
190
191
  }
191
192
 
192
193
  /** Builds a string command option. */
193
- export class StringOptionBuilder extends CommandOptionBuilder {
194
+ export class CreateStringOption extends CreateCommandOption {
194
195
  /** Creates a string option. */ public constructor() {
195
- super(ApplicationCommandOptionType.String);
196
+ super(ApplicationCommandOptionEnum.String);
196
197
  }
197
198
  /** Adds string choices. */ public addChoices(
198
199
  ...choices: Array<{ name: string; value: string }>
@@ -237,9 +238,9 @@ export class StringOptionBuilder extends CommandOptionBuilder {
237
238
  }
238
239
  }
239
240
  /** Builds an integer command option. */
240
- export class IntegerOptionBuilder extends CommandOptionBuilder {
241
+ export class CreateIntegerOption extends CreateCommandOption {
241
242
  public constructor() {
242
- super(ApplicationCommandOptionType.Integer);
243
+ super(ApplicationCommandOptionEnum.Integer);
243
244
  }
244
245
  public setMinValue(value: number): this {
245
246
  validateNumberRange(
@@ -293,9 +294,9 @@ export class IntegerOptionBuilder extends CommandOptionBuilder {
293
294
  }
294
295
  }
295
296
  /** Builds a number command option. */
296
- export class NumberOptionBuilder extends CommandOptionBuilder {
297
+ export class CreateNumberOption extends CreateCommandOption {
297
298
  public constructor() {
298
- super(ApplicationCommandOptionType.Number);
299
+ super(ApplicationCommandOptionEnum.Number);
299
300
  }
300
301
  public setMinValue(value: number): this {
301
302
  validateNumberRange(
@@ -348,34 +349,34 @@ export class NumberOptionBuilder extends CommandOptionBuilder {
348
349
  return this;
349
350
  }
350
351
  }
351
- /** Builds a boolean command option. */ export class BooleanOptionBuilder extends CommandOptionBuilder {
352
+ /** Builds a boolean command option. */ export class CreateBooleanOption extends CreateCommandOption {
352
353
  /** Creates a boolean option. */ public constructor() {
353
- super(ApplicationCommandOptionType.Boolean);
354
+ super(ApplicationCommandOptionEnum.Boolean);
354
355
  }
355
356
  }
356
- /** Builds a user command option. */ export class UserOptionBuilder extends CommandOptionBuilder {
357
+ /** Builds a user command option. */ export class CreateUserOption extends CreateCommandOption {
357
358
  /** Creates a user option. */ public constructor() {
358
- super(ApplicationCommandOptionType.User);
359
+ super(ApplicationCommandOptionEnum.User);
359
360
  }
360
361
  }
361
- /** Builds a role command option. */ export class RoleOptionBuilder extends CommandOptionBuilder {
362
+ /** Builds a role command option. */ export class CreateRoleOption extends CreateCommandOption {
362
363
  /** Creates a role option. */ public constructor() {
363
- super(ApplicationCommandOptionType.Role);
364
+ super(ApplicationCommandOptionEnum.Role);
364
365
  }
365
366
  }
366
- /** Builds a mentionable command option. */ export class MentionableOptionBuilder extends CommandOptionBuilder {
367
+ /** Builds a mentionable command option. */ export class CreateMentionableOption extends CreateCommandOption {
367
368
  /** Creates a mentionable option. */ public constructor() {
368
- super(ApplicationCommandOptionType.Mentionable);
369
+ super(ApplicationCommandOptionEnum.Mentionable);
369
370
  }
370
371
  }
371
- /** Builds an attachment command option. */ export class AttachmentOptionBuilder extends CommandOptionBuilder {
372
+ /** Builds an attachment command option. */ export class CreateAttachmentOption extends CreateCommandOption {
372
373
  /** Creates an attachment option. */ public constructor() {
373
- super(ApplicationCommandOptionType.Attachment);
374
+ super(ApplicationCommandOptionEnum.Attachment);
374
375
  }
375
376
  }
376
- /** Builds a channel command option. */ export class ChannelOptionBuilder extends CommandOptionBuilder {
377
+ /** Builds a channel command option. */ export class CreateChannelOption extends CreateCommandOption {
377
378
  /** Creates a channel option. */ public constructor() {
378
- super(ApplicationCommandOptionType.Channel);
379
+ super(ApplicationCommandOptionEnum.Channel);
379
380
  }
380
381
  /** Restricts accepted channel types. */ public addChannelTypes(
381
382
  ...types: number[]
@@ -388,58 +389,56 @@ export class NumberOptionBuilder extends CommandOptionBuilder {
388
389
  return this;
389
390
  }
390
391
  }
391
- /** Builds a nested subcommand. */ export class SubcommandBuilder extends CommandOptionBuilder {
392
+ /** Builds a nested subcommand. */ export class CreateSubcommand extends CreateCommandOption {
392
393
  /** Creates a subcommand. */ public constructor() {
393
- super(ApplicationCommandOptionType.Subcommand);
394
+ super(ApplicationCommandOptionEnum.Subcommand);
394
395
  }
395
396
  /** Adds a string option to this subcommand. */ public addStringOption(
396
- configure: (option: StringOptionBuilder) => StringOptionBuilder,
397
+ configure: (option: CreateStringOption) => CreateStringOption,
397
398
  ): this {
398
- return this.addChildOption(configure(new StringOptionBuilder()));
399
+ return this.addChildOption(configure(new CreateStringOption()));
399
400
  }
400
401
  /** Adds an integer option to this subcommand. */ public addIntegerOption(
401
- configure: (option: IntegerOptionBuilder) => IntegerOptionBuilder,
402
+ configure: (option: CreateIntegerOption) => CreateIntegerOption,
402
403
  ): this {
403
- return this.addChildOption(configure(new IntegerOptionBuilder()));
404
+ return this.addChildOption(configure(new CreateIntegerOption()));
404
405
  }
405
406
  /** Adds a number option to this subcommand. */ public addNumberOption(
406
- configure: (option: NumberOptionBuilder) => NumberOptionBuilder,
407
+ configure: (option: CreateNumberOption) => CreateNumberOption,
407
408
  ): this {
408
- return this.addChildOption(configure(new NumberOptionBuilder()));
409
+ return this.addChildOption(configure(new CreateNumberOption()));
409
410
  }
410
411
  /** Adds a boolean option to this subcommand. */ public addBooleanOption(
411
- configure: (option: BooleanOptionBuilder) => BooleanOptionBuilder,
412
+ configure: (option: CreateBooleanOption) => CreateBooleanOption,
412
413
  ): this {
413
- return this.addChildOption(configure(new BooleanOptionBuilder()));
414
+ return this.addChildOption(configure(new CreateBooleanOption()));
414
415
  }
415
416
  /** Adds a user option to this subcommand. */ public addUserOption(
416
- configure: (option: UserOptionBuilder) => UserOptionBuilder,
417
+ configure: (option: CreateUserOption) => CreateUserOption,
417
418
  ): this {
418
- return this.addChildOption(configure(new UserOptionBuilder()));
419
+ return this.addChildOption(configure(new CreateUserOption()));
419
420
  }
420
421
  /** Adds a channel option to this subcommand. */ public addChannelOption(
421
- configure: (option: ChannelOptionBuilder) => ChannelOptionBuilder,
422
+ configure: (option: CreateChannelOption) => CreateChannelOption,
422
423
  ): this {
423
- return this.addChildOption(configure(new ChannelOptionBuilder()));
424
+ return this.addChildOption(configure(new CreateChannelOption()));
424
425
  }
425
426
  /** Adds a role option to this subcommand. */ public addRoleOption(
426
- configure: (option: RoleOptionBuilder) => RoleOptionBuilder,
427
+ configure: (option: CreateRoleOption) => CreateRoleOption,
427
428
  ): this {
428
- return this.addChildOption(configure(new RoleOptionBuilder()));
429
+ return this.addChildOption(configure(new CreateRoleOption()));
429
430
  }
430
431
  /** Adds a mentionable option to this subcommand. */ public addMentionableOption(
431
- configure: (
432
- option: MentionableOptionBuilder,
433
- ) => MentionableOptionBuilder,
432
+ configure: (option: CreateMentionableOption) => CreateMentionableOption,
434
433
  ): this {
435
- return this.addChildOption(configure(new MentionableOptionBuilder()));
434
+ return this.addChildOption(configure(new CreateMentionableOption()));
436
435
  }
437
436
  /** Adds an attachment option to this subcommand. */ public addAttachmentOption(
438
- configure: (option: AttachmentOptionBuilder) => AttachmentOptionBuilder,
437
+ configure: (option: CreateAttachmentOption) => CreateAttachmentOption,
439
438
  ): this {
440
- return this.addChildOption(configure(new AttachmentOptionBuilder()));
439
+ return this.addChildOption(configure(new CreateAttachmentOption()));
441
440
  }
442
- protected addChildOption(option: CommandOptionBuilder): this {
441
+ protected addChildOption(option: CreateCommandOption): this {
443
442
  const options = (this.data.options as unknown[] | undefined) ?? [];
444
443
  if (options.length >= 25)
445
444
  throw new RangeError(
@@ -469,7 +468,7 @@ export class NumberOptionBuilder extends CommandOptionBuilder {
469
468
  options.some(
470
469
  (existing) =>
471
470
  (existing as Record<string, unknown>).type ===
472
- ApplicationCommandOptionType.Subcommand,
471
+ ApplicationCommandOptionEnum.Subcommand,
473
472
  )
474
473
  )
475
474
  throw new RangeError(
@@ -480,19 +479,19 @@ export class NumberOptionBuilder extends CommandOptionBuilder {
480
479
  return this;
481
480
  }
482
481
  }
483
- /** Builds a nested subcommand group. */ export class SubcommandGroupBuilder extends CommandOptionBuilder {
482
+ /** Builds a nested subcommand group. */ export class CreateSubcommandGroup extends CreateCommandOption {
484
483
  /** Creates a subcommand group. */ public constructor() {
485
- super(ApplicationCommandOptionType.SubcommandGroup);
484
+ super(ApplicationCommandOptionEnum.SubcommandGroup);
486
485
  }
487
486
  /** Adds a subcommand to this group. */ public addSubcommand(
488
- configure: (option: SubcommandBuilder) => SubcommandBuilder,
487
+ configure: (option: CreateSubcommand) => CreateSubcommand,
489
488
  ): this {
490
489
  const options = (this.data.options as unknown[] | undefined) ?? [];
491
490
  if (options.length >= 25)
492
491
  throw new RangeError(
493
492
  "A subcommand group cannot contain more than 25 subcommands.",
494
493
  );
495
- const payload = configure(new SubcommandBuilder()).toJSON();
494
+ const payload = configure(new CreateSubcommand()).toJSON();
496
495
  if (
497
496
  options.some(
498
497
  (existing) =>
@@ -502,7 +501,7 @@ export class NumberOptionBuilder extends CommandOptionBuilder {
502
501
  throw new RangeError(
503
502
  `Duplicate subcommand name: ${String(payload.name)}.`,
504
503
  );
505
- if (payload.type !== ApplicationCommandOptionType.Subcommand)
504
+ if (payload.type !== ApplicationCommandOptionEnum.Subcommand)
506
505
  throw new TypeError(
507
506
  "Subcommand group children must be subcommands.",
508
507
  );
@@ -553,8 +552,8 @@ function validateNumberRange(
553
552
  // ─── Context Menu Builders ────────────────────────────────────────────────────
554
553
 
555
554
  /** Builder for application commands that appear in right-click context menus.
556
- * Discord.js-familiar: `new ContextMenuCommandBuilder().setName("x").setType(2)`. */
557
- export class ContextMenuCommandBuilder {
555
+ * Discord.js-familiar: `new CreateContextMenuCommand().setName("x").setType(2)`. */
556
+ export class CreateContextMenuCommand {
558
557
  protected readonly data: Record<string, unknown>;
559
558
  public constructor(type: 2 | 3 = 2) {
560
559
  this.data = { type };
@@ -597,11 +596,30 @@ export class ContextMenuCommandBuilder {
597
596
  this.data.dm_permission = enabled;
598
597
  return this;
599
598
  }
600
- /** Sets command integration types. */
599
+ /** Sets command integration types (0 guild install, 1 user install). */
601
600
  public setIntegrationTypes(...types: number[]): this {
602
601
  this.data.integration_types = [...types];
603
602
  return this;
604
603
  }
604
+ /** Sets where the command can be used: 0 guilds, 1 the bot's DMs, 2 other DMs. @throws {RangeError} For any other value. */
605
+ public setContexts(...contexts: number[]): this {
606
+ if (
607
+ contexts.some(
608
+ (context) => context !== 0 && context !== 1 && context !== 2,
609
+ )
610
+ )
611
+ throw new RangeError("Command contexts must be 0, 1 or 2.");
612
+ this.data.contexts = [...contexts];
613
+ return this;
614
+ }
615
+ /** Sets the name shown per locale, e.g. `{ "es-ES": "Ver perfil" }`; null clears it. */
616
+ public setNameLocalizations(
617
+ localizations: Record<string, string> | null,
618
+ ): this {
619
+ this.data.name_localizations =
620
+ localizations === null ? null : { ...localizations };
621
+ return this;
622
+ }
605
623
  /** Serializes the command payload for the Discord API. */
606
624
  public toJSON(): Record<string, unknown> {
607
625
  return structuredClone(this.data);
@@ -610,9 +628,9 @@ export class ContextMenuCommandBuilder {
610
628
 
611
629
  /** Builds a User context menu command (appears when right-clicking a user, type 2).
612
630
  * @example
613
- * new UserCommandBuilder().setName("View Profile").toJSON()
631
+ * new CreateUserCommand().setName("View Profile").toJSON()
614
632
  */
615
- export class UserCommandBuilder extends ContextMenuCommandBuilder {
633
+ export class CreateUserCommand extends CreateContextMenuCommand {
616
634
  public constructor() {
617
635
  super(2);
618
636
  }
@@ -620,10 +638,99 @@ export class UserCommandBuilder extends ContextMenuCommandBuilder {
620
638
 
621
639
  /** Builds a Message context menu command (appears when right-clicking a message, type 3).
622
640
  * @example
623
- * new MessageCommandBuilder().setName("Translate Message").toJSON()
641
+ * new CreateMessageCommand().setName("Translate Message").toJSON()
624
642
  */
625
- export class MessageCommandBuilder extends ContextMenuCommandBuilder {
643
+ export class CreateMessageCommand extends CreateContextMenuCommand {
626
644
  public constructor() {
627
645
  super(3);
628
646
  }
629
647
  }
648
+
649
+ // ─── Deprecated names (0.2.2), removed in 2.0 ────────────────────────────────
650
+ // Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
651
+ // `…Type` and `…Type` became `…Enum`.
652
+
653
+ /** @deprecated Use {@link CreateAttachmentOption}. Removed in 2.0. */
654
+ export const AttachmentOptionBuilder = CreateAttachmentOption;
655
+ /** @deprecated Use {@link CreateAttachmentOption}. Removed in 2.0. */
656
+ export type AttachmentOptionBuilder = CreateAttachmentOption;
657
+
658
+ /** @deprecated Use {@link CreateBooleanOption}. Removed in 2.0. */
659
+ export const BooleanOptionBuilder = CreateBooleanOption;
660
+ /** @deprecated Use {@link CreateBooleanOption}. Removed in 2.0. */
661
+ export type BooleanOptionBuilder = CreateBooleanOption;
662
+
663
+ /** @deprecated Use {@link CreateChannelOption}. Removed in 2.0. */
664
+ export const ChannelOptionBuilder = CreateChannelOption;
665
+ /** @deprecated Use {@link CreateChannelOption}. Removed in 2.0. */
666
+ export type ChannelOptionBuilder = CreateChannelOption;
667
+
668
+ /** @deprecated Use {@link CreateCommandOption}. Removed in 2.0. */
669
+ export const CommandOptionBuilder = CreateCommandOption;
670
+ /** @deprecated Use {@link CreateCommandOption}. Removed in 2.0. */
671
+ export type CommandOptionBuilder = CreateCommandOption;
672
+
673
+ /** @deprecated Use {@link CreateContextMenuCommand}. Removed in 2.0. */
674
+ export const ContextMenuCommandBuilder = CreateContextMenuCommand;
675
+ /** @deprecated Use {@link CreateContextMenuCommand}. Removed in 2.0. */
676
+ export type ContextMenuCommandBuilder = CreateContextMenuCommand;
677
+
678
+ /** @deprecated Use {@link CreateIntegerOption}. Removed in 2.0. */
679
+ export const IntegerOptionBuilder = CreateIntegerOption;
680
+ /** @deprecated Use {@link CreateIntegerOption}. Removed in 2.0. */
681
+ export type IntegerOptionBuilder = CreateIntegerOption;
682
+
683
+ /** @deprecated Use {@link CreateMentionableOption}. Removed in 2.0. */
684
+ export const MentionableOptionBuilder = CreateMentionableOption;
685
+ /** @deprecated Use {@link CreateMentionableOption}. Removed in 2.0. */
686
+ export type MentionableOptionBuilder = CreateMentionableOption;
687
+
688
+ /** @deprecated Use {@link CreateMessageCommand}. Removed in 2.0. */
689
+ export const MessageCommandBuilder = CreateMessageCommand;
690
+ /** @deprecated Use {@link CreateMessageCommand}. Removed in 2.0. */
691
+ export type MessageCommandBuilder = CreateMessageCommand;
692
+
693
+ /** @deprecated Use {@link CreateNumberOption}. Removed in 2.0. */
694
+ export const NumberOptionBuilder = CreateNumberOption;
695
+ /** @deprecated Use {@link CreateNumberOption}. Removed in 2.0. */
696
+ export type NumberOptionBuilder = CreateNumberOption;
697
+
698
+ /** @deprecated Use {@link CreateRoleOption}. Removed in 2.0. */
699
+ export const RoleOptionBuilder = CreateRoleOption;
700
+ /** @deprecated Use {@link CreateRoleOption}. Removed in 2.0. */
701
+ export type RoleOptionBuilder = CreateRoleOption;
702
+
703
+ /** @deprecated Use {@link CreateSlashCommand}. Removed in 2.0. */
704
+ export const SlashCommandBuilder = CreateSlashCommand;
705
+ /** @deprecated Use {@link CreateSlashCommand}. Removed in 2.0. */
706
+ export type SlashCommandBuilder = CreateSlashCommand;
707
+
708
+ /** @deprecated Use {@link CreateStringOption}. Removed in 2.0. */
709
+ export const StringOptionBuilder = CreateStringOption;
710
+ /** @deprecated Use {@link CreateStringOption}. Removed in 2.0. */
711
+ export type StringOptionBuilder = CreateStringOption;
712
+
713
+ /** @deprecated Use {@link CreateSubcommand}. Removed in 2.0. */
714
+ export const SubcommandBuilder = CreateSubcommand;
715
+ /** @deprecated Use {@link CreateSubcommand}. Removed in 2.0. */
716
+ export type SubcommandBuilder = CreateSubcommand;
717
+
718
+ /** @deprecated Use {@link CreateSubcommandGroup}. Removed in 2.0. */
719
+ export const SubcommandGroupBuilder = CreateSubcommandGroup;
720
+ /** @deprecated Use {@link CreateSubcommandGroup}. Removed in 2.0. */
721
+ export type SubcommandGroupBuilder = CreateSubcommandGroup;
722
+
723
+ /** @deprecated Use {@link CreateUserCommand}. Removed in 2.0. */
724
+ export const UserCommandBuilder = CreateUserCommand;
725
+ /** @deprecated Use {@link CreateUserCommand}. Removed in 2.0. */
726
+ export type UserCommandBuilder = CreateUserCommand;
727
+
728
+ /** @deprecated Use {@link CreateUserOption}. Removed in 2.0. */
729
+ export const UserOptionBuilder = CreateUserOption;
730
+ /** @deprecated Use {@link CreateUserOption}. Removed in 2.0. */
731
+ export type UserOptionBuilder = CreateUserOption;
732
+
733
+ /** @deprecated Use {@link ApplicationCommandOptionEnum}. Removed in 2.0. */
734
+ export const ApplicationCommandOptionType = ApplicationCommandOptionEnum;
735
+ /** @deprecated Use {@link ApplicationCommandOptionEnum}. Removed in 2.0. */
736
+ export type ApplicationCommandOptionType = ApplicationCommandOptionEnum;