@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 +24 -24
- package/package.json +1 -1
- package/src/attachment.ts +10 -1
- package/src/commands.ts +189 -82
- package/src/components.ts +200 -85
- package/src/embed.ts +10 -1
- package/src/index.ts +102 -34
package/README.md
CHANGED
|
@@ -8,31 +8,31 @@ bun add @lunibee/builders
|
|
|
8
8
|
|
|
9
9
|
```ts
|
|
10
10
|
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
11
|
+
CreateEmbed,
|
|
12
|
+
CreateActionRow,
|
|
13
|
+
CreateButton,
|
|
14
|
+
ButtonType,
|
|
15
|
+
CreateStringSelectMenu,
|
|
16
|
+
CreateSlashCommand,
|
|
17
17
|
} from "@lunibee/builders";
|
|
18
18
|
|
|
19
|
-
const embed = new
|
|
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
|
|
26
|
-
new
|
|
25
|
+
const buttons = new CreateActionRow().addComponents(
|
|
26
|
+
new CreateButton().setCustomId("yes").setLabel("Yes").setStyle(ButtonType.Success),
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
const menu = new
|
|
30
|
-
new
|
|
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
|
|
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 | `
|
|
48
|
-
| Buttons & rows | `
|
|
49
|
-
| Select menus | `
|
|
50
|
-
| Modals | `
|
|
51
|
-
| Slash commands | `
|
|
52
|
-
| Context menus | `
|
|
53
|
-
| Components V2 | `
|
|
54
|
-
| Files | `
|
|
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
|
-
- `
|
|
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
|
-
- `
|
|
63
|
-
- `
|
|
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); `
|
|
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
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
|
|
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
|
|
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
|
|
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:
|
|
63
|
+
configure: (option: CreateStringOption) => CreateStringOption,
|
|
61
64
|
): this {
|
|
62
|
-
return this.addOption(configure(new
|
|
65
|
+
return this.addOption(configure(new CreateStringOption()));
|
|
63
66
|
}
|
|
64
67
|
/** Adds an integer option. */ public addIntegerOption(
|
|
65
|
-
configure: (option:
|
|
68
|
+
configure: (option: CreateIntegerOption) => CreateIntegerOption,
|
|
66
69
|
): this {
|
|
67
|
-
return this.addOption(configure(new
|
|
70
|
+
return this.addOption(configure(new CreateIntegerOption()));
|
|
68
71
|
}
|
|
69
72
|
/** Adds a number option. */ public addNumberOption(
|
|
70
|
-
configure: (option:
|
|
73
|
+
configure: (option: CreateNumberOption) => CreateNumberOption,
|
|
71
74
|
): this {
|
|
72
|
-
return this.addOption(configure(new
|
|
75
|
+
return this.addOption(configure(new CreateNumberOption()));
|
|
73
76
|
}
|
|
74
77
|
/** Adds a boolean option. */ public addBooleanOption(
|
|
75
|
-
configure: (option:
|
|
78
|
+
configure: (option: CreateBooleanOption) => CreateBooleanOption,
|
|
76
79
|
): this {
|
|
77
|
-
return this.addOption(configure(new
|
|
80
|
+
return this.addOption(configure(new CreateBooleanOption()));
|
|
78
81
|
}
|
|
79
82
|
/** Adds a user option. */ public addUserOption(
|
|
80
|
-
configure: (option:
|
|
83
|
+
configure: (option: CreateUserOption) => CreateUserOption,
|
|
81
84
|
): this {
|
|
82
|
-
return this.addOption(configure(new
|
|
85
|
+
return this.addOption(configure(new CreateUserOption()));
|
|
83
86
|
}
|
|
84
87
|
/** Adds a channel option. */ public addChannelOption(
|
|
85
|
-
configure: (option:
|
|
88
|
+
configure: (option: CreateChannelOption) => CreateChannelOption,
|
|
86
89
|
): this {
|
|
87
|
-
return this.addOption(configure(new
|
|
90
|
+
return this.addOption(configure(new CreateChannelOption()));
|
|
88
91
|
}
|
|
89
92
|
/** Adds a role option. */ public addRoleOption(
|
|
90
|
-
configure: (option:
|
|
93
|
+
configure: (option: CreateRoleOption) => CreateRoleOption,
|
|
91
94
|
): this {
|
|
92
|
-
return this.addOption(configure(new
|
|
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
|
|
100
|
+
return this.addOption(configure(new CreateMentionableOption()));
|
|
100
101
|
}
|
|
101
102
|
/** Adds an attachment option. */ public addAttachmentOption(
|
|
102
|
-
configure: (option:
|
|
103
|
+
configure: (option: CreateAttachmentOption) => CreateAttachmentOption,
|
|
103
104
|
): this {
|
|
104
|
-
return this.addOption(configure(new
|
|
105
|
+
return this.addOption(configure(new CreateAttachmentOption()));
|
|
105
106
|
}
|
|
106
107
|
/** Adds a subcommand. */ public addSubcommand(
|
|
107
|
-
configure: (option:
|
|
108
|
+
configure: (option: CreateSubcommand) => CreateSubcommand,
|
|
108
109
|
): this {
|
|
109
|
-
return this.addOption(configure(new
|
|
110
|
+
return this.addOption(configure(new CreateSubcommand()));
|
|
110
111
|
}
|
|
111
112
|
/** Adds a subcommand group. */ public addSubcommandGroup(
|
|
112
|
-
configure: (option:
|
|
113
|
+
configure: (option: CreateSubcommandGroup) => CreateSubcommandGroup,
|
|
113
114
|
): this {
|
|
114
|
-
return this.addOption(configure(new
|
|
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:
|
|
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
|
|
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
|
|
194
|
+
export class CreateStringOption extends CreateCommandOption {
|
|
194
195
|
/** Creates a string option. */ public constructor() {
|
|
195
|
-
super(
|
|
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
|
|
241
|
+
export class CreateIntegerOption extends CreateCommandOption {
|
|
241
242
|
public constructor() {
|
|
242
|
-
super(
|
|
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
|
|
297
|
+
export class CreateNumberOption extends CreateCommandOption {
|
|
297
298
|
public constructor() {
|
|
298
|
-
super(
|
|
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
|
|
352
|
+
/** Builds a boolean command option. */ export class CreateBooleanOption extends CreateCommandOption {
|
|
352
353
|
/** Creates a boolean option. */ public constructor() {
|
|
353
|
-
super(
|
|
354
|
+
super(ApplicationCommandOptionEnum.Boolean);
|
|
354
355
|
}
|
|
355
356
|
}
|
|
356
|
-
/** Builds a user command option. */ export class
|
|
357
|
+
/** Builds a user command option. */ export class CreateUserOption extends CreateCommandOption {
|
|
357
358
|
/** Creates a user option. */ public constructor() {
|
|
358
|
-
super(
|
|
359
|
+
super(ApplicationCommandOptionEnum.User);
|
|
359
360
|
}
|
|
360
361
|
}
|
|
361
|
-
/** Builds a role command option. */ export class
|
|
362
|
+
/** Builds a role command option. */ export class CreateRoleOption extends CreateCommandOption {
|
|
362
363
|
/** Creates a role option. */ public constructor() {
|
|
363
|
-
super(
|
|
364
|
+
super(ApplicationCommandOptionEnum.Role);
|
|
364
365
|
}
|
|
365
366
|
}
|
|
366
|
-
/** Builds a mentionable command option. */ export class
|
|
367
|
+
/** Builds a mentionable command option. */ export class CreateMentionableOption extends CreateCommandOption {
|
|
367
368
|
/** Creates a mentionable option. */ public constructor() {
|
|
368
|
-
super(
|
|
369
|
+
super(ApplicationCommandOptionEnum.Mentionable);
|
|
369
370
|
}
|
|
370
371
|
}
|
|
371
|
-
/** Builds an attachment command option. */ export class
|
|
372
|
+
/** Builds an attachment command option. */ export class CreateAttachmentOption extends CreateCommandOption {
|
|
372
373
|
/** Creates an attachment option. */ public constructor() {
|
|
373
|
-
super(
|
|
374
|
+
super(ApplicationCommandOptionEnum.Attachment);
|
|
374
375
|
}
|
|
375
376
|
}
|
|
376
|
-
/** Builds a channel command option. */ export class
|
|
377
|
+
/** Builds a channel command option. */ export class CreateChannelOption extends CreateCommandOption {
|
|
377
378
|
/** Creates a channel option. */ public constructor() {
|
|
378
|
-
super(
|
|
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
|
|
392
|
+
/** Builds a nested subcommand. */ export class CreateSubcommand extends CreateCommandOption {
|
|
392
393
|
/** Creates a subcommand. */ public constructor() {
|
|
393
|
-
super(
|
|
394
|
+
super(ApplicationCommandOptionEnum.Subcommand);
|
|
394
395
|
}
|
|
395
396
|
/** Adds a string option to this subcommand. */ public addStringOption(
|
|
396
|
-
configure: (option:
|
|
397
|
+
configure: (option: CreateStringOption) => CreateStringOption,
|
|
397
398
|
): this {
|
|
398
|
-
return this.addChildOption(configure(new
|
|
399
|
+
return this.addChildOption(configure(new CreateStringOption()));
|
|
399
400
|
}
|
|
400
401
|
/** Adds an integer option to this subcommand. */ public addIntegerOption(
|
|
401
|
-
configure: (option:
|
|
402
|
+
configure: (option: CreateIntegerOption) => CreateIntegerOption,
|
|
402
403
|
): this {
|
|
403
|
-
return this.addChildOption(configure(new
|
|
404
|
+
return this.addChildOption(configure(new CreateIntegerOption()));
|
|
404
405
|
}
|
|
405
406
|
/** Adds a number option to this subcommand. */ public addNumberOption(
|
|
406
|
-
configure: (option:
|
|
407
|
+
configure: (option: CreateNumberOption) => CreateNumberOption,
|
|
407
408
|
): this {
|
|
408
|
-
return this.addChildOption(configure(new
|
|
409
|
+
return this.addChildOption(configure(new CreateNumberOption()));
|
|
409
410
|
}
|
|
410
411
|
/** Adds a boolean option to this subcommand. */ public addBooleanOption(
|
|
411
|
-
configure: (option:
|
|
412
|
+
configure: (option: CreateBooleanOption) => CreateBooleanOption,
|
|
412
413
|
): this {
|
|
413
|
-
return this.addChildOption(configure(new
|
|
414
|
+
return this.addChildOption(configure(new CreateBooleanOption()));
|
|
414
415
|
}
|
|
415
416
|
/** Adds a user option to this subcommand. */ public addUserOption(
|
|
416
|
-
configure: (option:
|
|
417
|
+
configure: (option: CreateUserOption) => CreateUserOption,
|
|
417
418
|
): this {
|
|
418
|
-
return this.addChildOption(configure(new
|
|
419
|
+
return this.addChildOption(configure(new CreateUserOption()));
|
|
419
420
|
}
|
|
420
421
|
/** Adds a channel option to this subcommand. */ public addChannelOption(
|
|
421
|
-
configure: (option:
|
|
422
|
+
configure: (option: CreateChannelOption) => CreateChannelOption,
|
|
422
423
|
): this {
|
|
423
|
-
return this.addChildOption(configure(new
|
|
424
|
+
return this.addChildOption(configure(new CreateChannelOption()));
|
|
424
425
|
}
|
|
425
426
|
/** Adds a role option to this subcommand. */ public addRoleOption(
|
|
426
|
-
configure: (option:
|
|
427
|
+
configure: (option: CreateRoleOption) => CreateRoleOption,
|
|
427
428
|
): this {
|
|
428
|
-
return this.addChildOption(configure(new
|
|
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
|
|
434
|
+
return this.addChildOption(configure(new CreateMentionableOption()));
|
|
436
435
|
}
|
|
437
436
|
/** Adds an attachment option to this subcommand. */ public addAttachmentOption(
|
|
438
|
-
configure: (option:
|
|
437
|
+
configure: (option: CreateAttachmentOption) => CreateAttachmentOption,
|
|
439
438
|
): this {
|
|
440
|
-
return this.addChildOption(configure(new
|
|
439
|
+
return this.addChildOption(configure(new CreateAttachmentOption()));
|
|
441
440
|
}
|
|
442
|
-
protected addChildOption(option:
|
|
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
|
-
|
|
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
|
|
482
|
+
/** Builds a nested subcommand group. */ export class CreateSubcommandGroup extends CreateCommandOption {
|
|
484
483
|
/** Creates a subcommand group. */ public constructor() {
|
|
485
|
-
super(
|
|
484
|
+
super(ApplicationCommandOptionEnum.SubcommandGroup);
|
|
486
485
|
}
|
|
487
486
|
/** Adds a subcommand to this group. */ public addSubcommand(
|
|
488
|
-
configure: (option:
|
|
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
|
|
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 !==
|
|
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
|
|
557
|
-
export class
|
|
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
|
|
631
|
+
* new CreateUserCommand().setName("View Profile").toJSON()
|
|
614
632
|
*/
|
|
615
|
-
export class
|
|
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
|
|
641
|
+
* new CreateMessageCommand().setName("Translate Message").toJSON()
|
|
624
642
|
*/
|
|
625
|
-
export class
|
|
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;
|