@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/src/components.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
// Re-export the canonical
|
|
1
|
+
// Re-export the canonical ButtonType from @lunibee/types so the builders package
|
|
2
2
|
// never ships a drifting duplicate (the old local copy was missing `Premium: 6`).
|
|
3
|
-
import {
|
|
4
|
-
export {
|
|
3
|
+
import { ButtonType } from "@lunibee/types";
|
|
4
|
+
export { ButtonType };
|
|
5
5
|
|
|
6
6
|
/** Component type constants exposed by Lunibee. */
|
|
7
|
-
export const
|
|
7
|
+
export const ComponentEnum = {
|
|
8
8
|
ActionRow: 1,
|
|
9
9
|
Button: 2,
|
|
10
10
|
StringSelect: 3,
|
|
@@ -22,19 +22,18 @@ export const ComponentType = {
|
|
|
22
22
|
ContentInventoryEntry: 16,
|
|
23
23
|
Container: 17,
|
|
24
24
|
} as const;
|
|
25
|
-
export const
|
|
26
|
-
/** One {@link
|
|
27
|
-
export type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export type ComponentType = (typeof ComponentType)[keyof typeof ComponentType];
|
|
25
|
+
export const TextInputType = { Short: 1, Paragraph: 2 } as const;
|
|
26
|
+
/** One {@link TextInputType} value, usable as a type. */
|
|
27
|
+
export type TextInputType = (typeof TextInputType)[keyof typeof TextInputType];
|
|
28
|
+
/** One {@link ComponentEnum} value, usable as a type. */
|
|
29
|
+
export type ComponentEnum = (typeof ComponentEnum)[keyof typeof ComponentEnum];
|
|
31
30
|
export interface APIComponentEmoji {
|
|
32
31
|
id?: string | null;
|
|
33
32
|
name?: string | null;
|
|
34
33
|
animated?: boolean;
|
|
35
34
|
}
|
|
36
35
|
export interface APIButtonComponent {
|
|
37
|
-
type: typeof
|
|
36
|
+
type: typeof ComponentEnum.Button;
|
|
38
37
|
style: 1 | 2 | 3 | 4 | 5 | 6;
|
|
39
38
|
custom_id?: string;
|
|
40
39
|
label?: string;
|
|
@@ -52,7 +51,7 @@ export interface APISelectOption {
|
|
|
52
51
|
default?: boolean;
|
|
53
52
|
}
|
|
54
53
|
export interface APIStringSelectComponent {
|
|
55
|
-
type: typeof
|
|
54
|
+
type: typeof ComponentEnum.StringSelect;
|
|
56
55
|
custom_id?: string;
|
|
57
56
|
placeholder?: string;
|
|
58
57
|
min_values?: number;
|
|
@@ -63,10 +62,10 @@ export interface APIStringSelectComponent {
|
|
|
63
62
|
}
|
|
64
63
|
export interface APIEntitySelectComponent {
|
|
65
64
|
type:
|
|
66
|
-
| typeof
|
|
67
|
-
| typeof
|
|
68
|
-
| typeof
|
|
69
|
-
| typeof
|
|
65
|
+
| typeof ComponentEnum.UserSelect
|
|
66
|
+
| typeof ComponentEnum.RoleSelect
|
|
67
|
+
| typeof ComponentEnum.MentionableSelect
|
|
68
|
+
| typeof ComponentEnum.ChannelSelect;
|
|
70
69
|
custom_id?: string;
|
|
71
70
|
placeholder?: string;
|
|
72
71
|
min_values?: number;
|
|
@@ -76,8 +75,8 @@ export interface APIEntitySelectComponent {
|
|
|
76
75
|
default_values?: APISelectDefaultValue[];
|
|
77
76
|
}
|
|
78
77
|
export interface APITextInputComponent {
|
|
79
|
-
type: typeof
|
|
80
|
-
style: typeof
|
|
78
|
+
type: typeof ComponentEnum.TextInput;
|
|
79
|
+
style: typeof TextInputType.Short | typeof TextInputType.Paragraph;
|
|
81
80
|
custom_id?: string;
|
|
82
81
|
label?: string;
|
|
83
82
|
placeholder?: string;
|
|
@@ -98,20 +97,20 @@ export type APIActionRowChild =
|
|
|
98
97
|
| APIEntitySelectComponent
|
|
99
98
|
| APITextInputComponent;
|
|
100
99
|
export interface APIActionRowComponent {
|
|
101
|
-
type: typeof
|
|
100
|
+
type: typeof ComponentEnum.ActionRow;
|
|
102
101
|
components: APIActionRowChild[];
|
|
103
102
|
}
|
|
104
103
|
export interface APISectionComponent {
|
|
105
|
-
type: typeof
|
|
104
|
+
type: typeof ComponentEnum.Section;
|
|
106
105
|
components?: APIComponent[]; // text displays
|
|
107
106
|
accessory?: APIComponent; // buttons, thumbnails, etc.
|
|
108
107
|
}
|
|
109
108
|
export interface APITextDisplayComponent {
|
|
110
|
-
type: typeof
|
|
109
|
+
type: typeof ComponentEnum.TextDisplay;
|
|
111
110
|
content: string;
|
|
112
111
|
}
|
|
113
112
|
export interface APIMediaGalleryComponent {
|
|
114
|
-
type: typeof
|
|
113
|
+
type: typeof ComponentEnum.MediaGallery;
|
|
115
114
|
items: { media: { url: string; description?: string } }[];
|
|
116
115
|
}
|
|
117
116
|
/** Default values accepted by an auto-populated entity select. */
|
|
@@ -120,17 +119,17 @@ export interface APISelectDefaultValue {
|
|
|
120
119
|
type: "user" | "role" | "channel";
|
|
121
120
|
}
|
|
122
121
|
export interface APIFileComponent {
|
|
123
|
-
type: typeof
|
|
122
|
+
type: typeof ComponentEnum.File;
|
|
124
123
|
file: { url: string };
|
|
125
124
|
spoiler?: boolean;
|
|
126
125
|
}
|
|
127
126
|
export interface APISeparatorComponent {
|
|
128
|
-
type: typeof
|
|
127
|
+
type: typeof ComponentEnum.Separator;
|
|
129
128
|
spacing?: 1 | 2;
|
|
130
129
|
divider?: boolean;
|
|
131
130
|
}
|
|
132
131
|
export interface APIThumbnailComponent {
|
|
133
|
-
type: typeof
|
|
132
|
+
type: typeof ComponentEnum.Thumbnail;
|
|
134
133
|
url: string;
|
|
135
134
|
proxy_url?: string;
|
|
136
135
|
width?: number;
|
|
@@ -139,11 +138,11 @@ export interface APIThumbnailComponent {
|
|
|
139
138
|
spoiler?: boolean;
|
|
140
139
|
}
|
|
141
140
|
export interface APIContentInventoryEntryComponent {
|
|
142
|
-
type: typeof
|
|
141
|
+
type: typeof ComponentEnum.ContentInventoryEntry;
|
|
143
142
|
id: string;
|
|
144
143
|
}
|
|
145
144
|
export interface APIContainerComponent {
|
|
146
|
-
type: typeof
|
|
145
|
+
type: typeof ComponentEnum.Container;
|
|
147
146
|
components: APIComponent[];
|
|
148
147
|
accent_color?: number;
|
|
149
148
|
spoiler?: boolean;
|
|
@@ -163,7 +162,7 @@ export type APIComponent =
|
|
|
163
162
|
| APIContentInventoryEntryComponent
|
|
164
163
|
| APIContainerComponent;
|
|
165
164
|
|
|
166
|
-
export class
|
|
165
|
+
export class CreateActionRow<
|
|
167
166
|
T extends { toJSON(): APIActionRowChild } = { toJSON(): APIActionRowChild },
|
|
168
167
|
> {
|
|
169
168
|
readonly #components: T[] = [];
|
|
@@ -189,18 +188,18 @@ export class ActionRowBuilder<
|
|
|
189
188
|
throw new RangeError("An action row needs at least one component.");
|
|
190
189
|
const types = components.map((component) => component.type);
|
|
191
190
|
if (
|
|
192
|
-
types.some((type) => type !==
|
|
191
|
+
types.some((type) => type !== ComponentEnum.Button) &&
|
|
193
192
|
components.length > 1
|
|
194
193
|
)
|
|
195
194
|
throw new RangeError(
|
|
196
195
|
"A select menu or text input must be alone in its action row.",
|
|
197
196
|
);
|
|
198
|
-
return { type:
|
|
197
|
+
return { type: ComponentEnum.ActionRow, components };
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
|
-
export class
|
|
200
|
+
export class CreateStringSelect {
|
|
202
201
|
readonly #data: APIStringSelectComponent = {
|
|
203
|
-
type:
|
|
202
|
+
type: ComponentEnum.StringSelect,
|
|
204
203
|
};
|
|
205
204
|
public setCustomId(value: string): this {
|
|
206
205
|
validateText(value, 100, "Component custom ID");
|
|
@@ -266,19 +265,19 @@ export class StringSelectBuilder {
|
|
|
266
265
|
return structuredClone(this.#data);
|
|
267
266
|
}
|
|
268
267
|
}
|
|
269
|
-
export class
|
|
268
|
+
export class CreateButton {
|
|
270
269
|
readonly #data: APIButtonComponent = {
|
|
271
|
-
type:
|
|
272
|
-
style:
|
|
270
|
+
type: ComponentEnum.Button,
|
|
271
|
+
style: ButtonType.Secondary,
|
|
273
272
|
};
|
|
274
273
|
/** Sets the style and drops fields that style cannot carry. */
|
|
275
274
|
public setStyle(style: APIButtonComponent["style"]): this {
|
|
276
275
|
const data = this.#data;
|
|
277
276
|
data.style = style;
|
|
278
|
-
if (style ===
|
|
277
|
+
if (style === ButtonType.Link) {
|
|
279
278
|
delete data.custom_id;
|
|
280
279
|
delete data.sku_id;
|
|
281
|
-
} else if (style ===
|
|
280
|
+
} else if (style === ButtonType.Premium) {
|
|
282
281
|
delete data.custom_id;
|
|
283
282
|
delete data.url;
|
|
284
283
|
delete data.label;
|
|
@@ -291,7 +290,7 @@ export class ButtonBuilder {
|
|
|
291
290
|
}
|
|
292
291
|
public setCustomId(value: string): this {
|
|
293
292
|
validateText(value, 100, "Button custom ID");
|
|
294
|
-
if (this.#data.style ===
|
|
293
|
+
if (this.#data.style === ButtonType.Link)
|
|
295
294
|
throw new TypeError("Link buttons cannot use custom IDs.");
|
|
296
295
|
this.#data.custom_id = value;
|
|
297
296
|
return this;
|
|
@@ -311,14 +310,14 @@ export class ButtonBuilder {
|
|
|
311
310
|
cause: error,
|
|
312
311
|
});
|
|
313
312
|
}
|
|
314
|
-
this.setStyle(
|
|
313
|
+
this.setStyle(ButtonType.Link);
|
|
315
314
|
this.#data.url = url.toString();
|
|
316
315
|
return this;
|
|
317
316
|
}
|
|
318
317
|
/** Makes this a premium (purchase) button for a SKU. Premium buttons carry no label, emoji, custom ID or URL. */
|
|
319
318
|
public setSKUId(skuId: string): this {
|
|
320
319
|
validateText(skuId, 20, "Button SKU ID");
|
|
321
|
-
this.setStyle(
|
|
320
|
+
this.setStyle(ButtonType.Premium);
|
|
322
321
|
this.#data.sku_id = skuId;
|
|
323
322
|
return this;
|
|
324
323
|
}
|
|
@@ -333,13 +332,13 @@ export class ButtonBuilder {
|
|
|
333
332
|
}
|
|
334
333
|
public toJSON(): APIButtonComponent {
|
|
335
334
|
const data = this.#data;
|
|
336
|
-
if (data.style ===
|
|
335
|
+
if (data.style === ButtonType.Link) {
|
|
337
336
|
if (!data.url) throw new TypeError("Link buttons require a URL.");
|
|
338
337
|
if (data.custom_id || data.sku_id)
|
|
339
338
|
throw new TypeError(
|
|
340
339
|
"Link buttons cannot have a custom ID or SKU ID.",
|
|
341
340
|
);
|
|
342
|
-
} else if (data.style ===
|
|
341
|
+
} else if (data.style === ButtonType.Premium) {
|
|
343
342
|
if (!data.sku_id)
|
|
344
343
|
throw new TypeError("Premium buttons require a SKU ID.");
|
|
345
344
|
if (data.custom_id || data.url || data.label || data.emoji)
|
|
@@ -354,25 +353,25 @@ export class ButtonBuilder {
|
|
|
354
353
|
"Only link buttons have a URL and only premium buttons have a SKU ID.",
|
|
355
354
|
);
|
|
356
355
|
}
|
|
357
|
-
if (data.style !==
|
|
356
|
+
if (data.style !== ButtonType.Premium && !data.label && !data.emoji)
|
|
358
357
|
throw new TypeError("Buttons require a label or an emoji.");
|
|
359
358
|
return structuredClone(data);
|
|
360
359
|
}
|
|
361
360
|
}
|
|
362
|
-
export class
|
|
361
|
+
export class CreateEntitySelect {
|
|
363
362
|
readonly #data: APIEntitySelectComponent;
|
|
364
363
|
public constructor(
|
|
365
364
|
type:
|
|
366
|
-
| typeof
|
|
367
|
-
| typeof
|
|
368
|
-
| typeof
|
|
369
|
-
| typeof
|
|
365
|
+
| typeof ComponentEnum.UserSelect
|
|
366
|
+
| typeof ComponentEnum.RoleSelect
|
|
367
|
+
| typeof ComponentEnum.MentionableSelect
|
|
368
|
+
| typeof ComponentEnum.ChannelSelect,
|
|
370
369
|
) {
|
|
371
370
|
if (
|
|
372
|
-
type !==
|
|
373
|
-
type !==
|
|
374
|
-
type !==
|
|
375
|
-
type !==
|
|
371
|
+
type !== ComponentEnum.UserSelect &&
|
|
372
|
+
type !== ComponentEnum.RoleSelect &&
|
|
373
|
+
type !== ComponentEnum.MentionableSelect &&
|
|
374
|
+
type !== ComponentEnum.ChannelSelect
|
|
376
375
|
)
|
|
377
376
|
throw new TypeError("Invalid select component type.");
|
|
378
377
|
this.#data = { type };
|
|
@@ -414,7 +413,7 @@ export class EntitySelectBuilder {
|
|
|
414
413
|
return structuredClone(this.#data);
|
|
415
414
|
}
|
|
416
415
|
}
|
|
417
|
-
export class
|
|
416
|
+
export class CreateModal {
|
|
418
417
|
readonly #components: Array<{ toJSON(): APIActionRowComponent }> = [];
|
|
419
418
|
#custom_id?: string;
|
|
420
419
|
#title?: string;
|
|
@@ -441,10 +440,10 @@ export class ModalBuilder {
|
|
|
441
440
|
return this;
|
|
442
441
|
}
|
|
443
442
|
/** Adds text inputs, each in its own action row (Discord's modal layout). @param inputs Text inputs, at most 5 per modal. */
|
|
444
|
-
public addTextInputs(...inputs:
|
|
443
|
+
public addTextInputs(...inputs: CreateTextInput[]): this {
|
|
445
444
|
return this.addComponents(
|
|
446
445
|
...inputs.map((input) =>
|
|
447
|
-
new
|
|
446
|
+
new CreateActionRow<CreateTextInput>().addComponents(input),
|
|
448
447
|
),
|
|
449
448
|
);
|
|
450
449
|
}
|
|
@@ -461,10 +460,10 @@ export class ModalBuilder {
|
|
|
461
460
|
};
|
|
462
461
|
}
|
|
463
462
|
}
|
|
464
|
-
export class
|
|
463
|
+
export class CreateTextInput {
|
|
465
464
|
readonly #data: APITextInputComponent = {
|
|
466
|
-
type:
|
|
467
|
-
style:
|
|
465
|
+
type: ComponentEnum.TextInput,
|
|
466
|
+
style: TextInputType.Short,
|
|
468
467
|
};
|
|
469
468
|
public setStyle(style: APITextInputComponent["style"]): this {
|
|
470
469
|
this.#data.style = style;
|
|
@@ -518,7 +517,7 @@ export class TextInputBuilder {
|
|
|
518
517
|
}
|
|
519
518
|
}
|
|
520
519
|
|
|
521
|
-
export class
|
|
520
|
+
export class CreateContainer {
|
|
522
521
|
readonly #components: { toJSON(): APIComponent }[] = [];
|
|
523
522
|
#accentColor?: number;
|
|
524
523
|
#spoiler?: boolean;
|
|
@@ -544,7 +543,7 @@ export class ContainerBuilder {
|
|
|
544
543
|
}
|
|
545
544
|
public toJSON(): APIContainerComponent {
|
|
546
545
|
const data: APIContainerComponent = {
|
|
547
|
-
type:
|
|
546
|
+
type: ComponentEnum.Container,
|
|
548
547
|
components: this.#components.map((c) => c.toJSON()),
|
|
549
548
|
};
|
|
550
549
|
if (this.#accentColor !== undefined)
|
|
@@ -554,7 +553,7 @@ export class ContainerBuilder {
|
|
|
554
553
|
}
|
|
555
554
|
}
|
|
556
555
|
|
|
557
|
-
export class
|
|
556
|
+
export class CreateSection {
|
|
558
557
|
readonly #components: { toJSON(): APIComponent }[] = [];
|
|
559
558
|
#accessory?: { toJSON(): APIComponent };
|
|
560
559
|
public addComponents(...components: { toJSON(): APIComponent }[]): this {
|
|
@@ -569,7 +568,7 @@ export class SectionBuilder {
|
|
|
569
568
|
}
|
|
570
569
|
public toJSON(): APISectionComponent {
|
|
571
570
|
return {
|
|
572
|
-
type:
|
|
571
|
+
type: ComponentEnum.Section,
|
|
573
572
|
components: this.#components.length
|
|
574
573
|
? this.#components.map((c) => c.toJSON())
|
|
575
574
|
: undefined,
|
|
@@ -578,7 +577,7 @@ export class SectionBuilder {
|
|
|
578
577
|
}
|
|
579
578
|
}
|
|
580
579
|
|
|
581
|
-
export class
|
|
580
|
+
export class CreateTextDisplay {
|
|
582
581
|
#content = "";
|
|
583
582
|
public setContent(content: string): this {
|
|
584
583
|
validateText(content, 4000, "Text display content");
|
|
@@ -587,13 +586,13 @@ export class TextDisplayBuilder {
|
|
|
587
586
|
}
|
|
588
587
|
public toJSON(): APITextDisplayComponent {
|
|
589
588
|
return {
|
|
590
|
-
type:
|
|
589
|
+
type: ComponentEnum.TextDisplay,
|
|
591
590
|
content: this.#content,
|
|
592
591
|
};
|
|
593
592
|
}
|
|
594
593
|
}
|
|
595
594
|
|
|
596
|
-
export class
|
|
595
|
+
export class CreateMediaGallery {
|
|
597
596
|
readonly #items: { media: { url: string; description?: string } }[] = [];
|
|
598
597
|
public addItems(...items: { url: string; description?: string }[]): this {
|
|
599
598
|
if (!items.length) {
|
|
@@ -609,13 +608,13 @@ export class MediaGalleryBuilder {
|
|
|
609
608
|
}
|
|
610
609
|
public toJSON(): APIMediaGalleryComponent {
|
|
611
610
|
return {
|
|
612
|
-
type:
|
|
611
|
+
type: ComponentEnum.MediaGallery,
|
|
613
612
|
items: structuredClone(this.#items),
|
|
614
613
|
};
|
|
615
614
|
}
|
|
616
615
|
}
|
|
617
616
|
|
|
618
|
-
export class
|
|
617
|
+
export class CreateFileComponent {
|
|
619
618
|
#url = "";
|
|
620
619
|
#spoiler?: boolean;
|
|
621
620
|
public setUrl(url: string): this {
|
|
@@ -630,7 +629,7 @@ export class FileComponentBuilder {
|
|
|
630
629
|
public toJSON(): APIFileComponent {
|
|
631
630
|
if (!this.#url) throw new Error("File component must have a URL.");
|
|
632
631
|
const data: APIFileComponent = {
|
|
633
|
-
type:
|
|
632
|
+
type: ComponentEnum.File,
|
|
634
633
|
file: { url: this.#url },
|
|
635
634
|
};
|
|
636
635
|
if (this.#spoiler !== undefined) data.spoiler = this.#spoiler;
|
|
@@ -638,7 +637,7 @@ export class FileComponentBuilder {
|
|
|
638
637
|
}
|
|
639
638
|
}
|
|
640
639
|
|
|
641
|
-
export class
|
|
640
|
+
export class CreateSeparator {
|
|
642
641
|
#spacing?: 1 | 2;
|
|
643
642
|
#divider?: boolean;
|
|
644
643
|
public setSpacing(spacing: 1 | 2): this {
|
|
@@ -651,7 +650,7 @@ export class SeparatorBuilder {
|
|
|
651
650
|
}
|
|
652
651
|
public toJSON(): APISeparatorComponent {
|
|
653
652
|
const data: APISeparatorComponent = {
|
|
654
|
-
type:
|
|
653
|
+
type: ComponentEnum.Separator,
|
|
655
654
|
};
|
|
656
655
|
if (this.#spacing !== undefined) data.spacing = this.#spacing;
|
|
657
656
|
if (this.#divider !== undefined) data.divider = this.#divider;
|
|
@@ -659,7 +658,7 @@ export class SeparatorBuilder {
|
|
|
659
658
|
}
|
|
660
659
|
}
|
|
661
660
|
|
|
662
|
-
export class
|
|
661
|
+
export class CreateThumbnail {
|
|
663
662
|
#url = "";
|
|
664
663
|
#description?: string;
|
|
665
664
|
#spoiler?: boolean;
|
|
@@ -681,7 +680,7 @@ export class ThumbnailBuilder {
|
|
|
681
680
|
}
|
|
682
681
|
public toJSON(): APIThumbnailComponent {
|
|
683
682
|
const data: APIThumbnailComponent = {
|
|
684
|
-
type:
|
|
683
|
+
type: ComponentEnum.Thumbnail,
|
|
685
684
|
url: this.#url,
|
|
686
685
|
};
|
|
687
686
|
if (this.#description !== undefined)
|
|
@@ -691,7 +690,7 @@ export class ThumbnailBuilder {
|
|
|
691
690
|
}
|
|
692
691
|
}
|
|
693
692
|
|
|
694
|
-
export class
|
|
693
|
+
export class CreateContentInventoryEntry {
|
|
695
694
|
#id = "";
|
|
696
695
|
public setId(id: string): this {
|
|
697
696
|
validateText(id, 100, "Content inventory entry ID");
|
|
@@ -700,7 +699,7 @@ export class ContentInventoryEntryBuilder {
|
|
|
700
699
|
}
|
|
701
700
|
public toJSON(): APIContentInventoryEntryComponent {
|
|
702
701
|
return {
|
|
703
|
-
type:
|
|
702
|
+
type: ComponentEnum.ContentInventoryEntry,
|
|
704
703
|
id: this.#id,
|
|
705
704
|
};
|
|
706
705
|
}
|
|
@@ -732,30 +731,30 @@ function validateLength(value: number, field: string, max = 4000): void {
|
|
|
732
731
|
);
|
|
733
732
|
}
|
|
734
733
|
|
|
735
|
-
/** Discord.js-familiar alias for {@link
|
|
736
|
-
export {
|
|
734
|
+
/** Discord.js-familiar alias for {@link CreateStringSelect}. */
|
|
735
|
+
export { CreateStringSelect as CreateStringSelectMenu };
|
|
737
736
|
/** User select menu builder (Discord.js-familiar). */
|
|
738
|
-
export class
|
|
737
|
+
export class CreateUserSelectMenu extends CreateEntitySelect {
|
|
739
738
|
public constructor() {
|
|
740
|
-
super(
|
|
739
|
+
super(ComponentEnum.UserSelect);
|
|
741
740
|
}
|
|
742
741
|
}
|
|
743
742
|
/** Role select menu builder (Discord.js-familiar). */
|
|
744
|
-
export class
|
|
743
|
+
export class CreateRoleSelectMenu extends CreateEntitySelect {
|
|
745
744
|
public constructor() {
|
|
746
|
-
super(
|
|
745
|
+
super(ComponentEnum.RoleSelect);
|
|
747
746
|
}
|
|
748
747
|
}
|
|
749
748
|
/** Mentionable select menu builder (Discord.js-familiar). */
|
|
750
|
-
export class
|
|
749
|
+
export class CreateMentionableSelectMenu extends CreateEntitySelect {
|
|
751
750
|
public constructor() {
|
|
752
|
-
super(
|
|
751
|
+
super(ComponentEnum.MentionableSelect);
|
|
753
752
|
}
|
|
754
753
|
}
|
|
755
754
|
/** Channel select menu builder (Discord.js-familiar). */
|
|
756
|
-
export class
|
|
755
|
+
export class CreateChannelSelectMenu extends CreateEntitySelect {
|
|
757
756
|
public constructor() {
|
|
758
|
-
super(
|
|
757
|
+
super(ComponentEnum.ChannelSelect);
|
|
759
758
|
}
|
|
760
759
|
}
|
|
761
760
|
|
|
@@ -779,7 +778,7 @@ const IS_COMPONENTS_V2 = 1 << 15;
|
|
|
779
778
|
* Discord requires for them. A V2 message cannot also carry `content` or `embeds`.
|
|
780
779
|
* @param components Top-level components (containers, sections, text displays, action rows...).
|
|
781
780
|
* @param options Extra message fields, such as `allowed_mentions` or `ephemeral`; `flags` are combined.
|
|
782
|
-
* @example channel.send(componentsV2Message(new
|
|
781
|
+
* @example channel.send(componentsV2Message(new CreateContainer().addComponents(new CreateTextDisplay().setContent("Hi"))))
|
|
783
782
|
*/
|
|
784
783
|
export function componentsV2Message<
|
|
785
784
|
T extends Record<string, unknown> = Record<string, never>,
|
|
@@ -798,3 +797,119 @@ export function componentsV2Message<
|
|
|
798
797
|
flags: (options?.flags ?? 0) | IS_COMPONENTS_V2,
|
|
799
798
|
};
|
|
800
799
|
}
|
|
800
|
+
|
|
801
|
+
// ─── Deprecated names (0.2.2), removed in 2.0 ────────────────────────────────
|
|
802
|
+
// Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
|
|
803
|
+
// `…Type` and `…Type` became `…Enum`.
|
|
804
|
+
|
|
805
|
+
/** @deprecated Use {@link CreateButton}. Removed in 2.0. */
|
|
806
|
+
export const ButtonBuilder = CreateButton;
|
|
807
|
+
/** @deprecated Use {@link CreateButton}. Removed in 2.0. */
|
|
808
|
+
export type ButtonBuilder = CreateButton;
|
|
809
|
+
|
|
810
|
+
/** @deprecated Use {@link CreateChannelSelectMenu}. Removed in 2.0. */
|
|
811
|
+
export const ChannelSelectMenuBuilder = CreateChannelSelectMenu;
|
|
812
|
+
/** @deprecated Use {@link CreateChannelSelectMenu}. Removed in 2.0. */
|
|
813
|
+
export type ChannelSelectMenuBuilder = CreateChannelSelectMenu;
|
|
814
|
+
|
|
815
|
+
/** @deprecated Use {@link CreateContainer}. Removed in 2.0. */
|
|
816
|
+
export const ContainerBuilder = CreateContainer;
|
|
817
|
+
/** @deprecated Use {@link CreateContainer}. Removed in 2.0. */
|
|
818
|
+
export type ContainerBuilder = CreateContainer;
|
|
819
|
+
|
|
820
|
+
/** @deprecated Use {@link CreateContentInventoryEntry}. Removed in 2.0. */
|
|
821
|
+
export const ContentInventoryEntryBuilder = CreateContentInventoryEntry;
|
|
822
|
+
/** @deprecated Use {@link CreateContentInventoryEntry}. Removed in 2.0. */
|
|
823
|
+
export type ContentInventoryEntryBuilder = CreateContentInventoryEntry;
|
|
824
|
+
|
|
825
|
+
/** @deprecated Use {@link CreateEntitySelect}. Removed in 2.0. */
|
|
826
|
+
export const EntitySelectBuilder = CreateEntitySelect;
|
|
827
|
+
/** @deprecated Use {@link CreateEntitySelect}. Removed in 2.0. */
|
|
828
|
+
export type EntitySelectBuilder = CreateEntitySelect;
|
|
829
|
+
|
|
830
|
+
/** @deprecated Use {@link CreateFileComponent}. Removed in 2.0. */
|
|
831
|
+
export const FileComponentBuilder = CreateFileComponent;
|
|
832
|
+
/** @deprecated Use {@link CreateFileComponent}. Removed in 2.0. */
|
|
833
|
+
export type FileComponentBuilder = CreateFileComponent;
|
|
834
|
+
|
|
835
|
+
/** @deprecated Use {@link CreateMediaGallery}. Removed in 2.0. */
|
|
836
|
+
export const MediaGalleryBuilder = CreateMediaGallery;
|
|
837
|
+
/** @deprecated Use {@link CreateMediaGallery}. Removed in 2.0. */
|
|
838
|
+
export type MediaGalleryBuilder = CreateMediaGallery;
|
|
839
|
+
|
|
840
|
+
/** @deprecated Use {@link CreateMentionableSelectMenu}. Removed in 2.0. */
|
|
841
|
+
export const MentionableSelectMenuBuilder = CreateMentionableSelectMenu;
|
|
842
|
+
/** @deprecated Use {@link CreateMentionableSelectMenu}. Removed in 2.0. */
|
|
843
|
+
export type MentionableSelectMenuBuilder = CreateMentionableSelectMenu;
|
|
844
|
+
|
|
845
|
+
/** @deprecated Use {@link CreateModal}. Removed in 2.0. */
|
|
846
|
+
export const ModalBuilder = CreateModal;
|
|
847
|
+
/** @deprecated Use {@link CreateModal}. Removed in 2.0. */
|
|
848
|
+
export type ModalBuilder = CreateModal;
|
|
849
|
+
|
|
850
|
+
/** @deprecated Use {@link CreateRoleSelectMenu}. Removed in 2.0. */
|
|
851
|
+
export const RoleSelectMenuBuilder = CreateRoleSelectMenu;
|
|
852
|
+
/** @deprecated Use {@link CreateRoleSelectMenu}. Removed in 2.0. */
|
|
853
|
+
export type RoleSelectMenuBuilder = CreateRoleSelectMenu;
|
|
854
|
+
|
|
855
|
+
/** @deprecated Use {@link CreateSection}. Removed in 2.0. */
|
|
856
|
+
export const SectionBuilder = CreateSection;
|
|
857
|
+
/** @deprecated Use {@link CreateSection}. Removed in 2.0. */
|
|
858
|
+
export type SectionBuilder = CreateSection;
|
|
859
|
+
|
|
860
|
+
/** @deprecated Use {@link CreateSeparator}. Removed in 2.0. */
|
|
861
|
+
export const SeparatorBuilder = CreateSeparator;
|
|
862
|
+
/** @deprecated Use {@link CreateSeparator}. Removed in 2.0. */
|
|
863
|
+
export type SeparatorBuilder = CreateSeparator;
|
|
864
|
+
|
|
865
|
+
/** @deprecated Use {@link CreateStringSelect}. Removed in 2.0. */
|
|
866
|
+
export const StringSelectBuilder = CreateStringSelect;
|
|
867
|
+
/** @deprecated Use {@link CreateStringSelect}. Removed in 2.0. */
|
|
868
|
+
export type StringSelectBuilder = CreateStringSelect;
|
|
869
|
+
|
|
870
|
+
/** @deprecated Use {@link CreateStringSelectMenu}. Removed in 2.0. */
|
|
871
|
+
export const StringSelectMenuBuilder = CreateStringSelect;
|
|
872
|
+
/** @deprecated Use {@link CreateStringSelectMenu}. Removed in 2.0. */
|
|
873
|
+
export type StringSelectMenuBuilder = CreateStringSelect;
|
|
874
|
+
|
|
875
|
+
/** @deprecated Use {@link CreateTextDisplay}. Removed in 2.0. */
|
|
876
|
+
export const TextDisplayBuilder = CreateTextDisplay;
|
|
877
|
+
/** @deprecated Use {@link CreateTextDisplay}. Removed in 2.0. */
|
|
878
|
+
export type TextDisplayBuilder = CreateTextDisplay;
|
|
879
|
+
|
|
880
|
+
/** @deprecated Use {@link CreateTextInput}. Removed in 2.0. */
|
|
881
|
+
export const TextInputBuilder = CreateTextInput;
|
|
882
|
+
/** @deprecated Use {@link CreateTextInput}. Removed in 2.0. */
|
|
883
|
+
export type TextInputBuilder = CreateTextInput;
|
|
884
|
+
|
|
885
|
+
/** @deprecated Use {@link CreateThumbnail}. Removed in 2.0. */
|
|
886
|
+
export const ThumbnailBuilder = CreateThumbnail;
|
|
887
|
+
/** @deprecated Use {@link CreateThumbnail}. Removed in 2.0. */
|
|
888
|
+
export type ThumbnailBuilder = CreateThumbnail;
|
|
889
|
+
|
|
890
|
+
/** @deprecated Use {@link CreateUserSelectMenu}. Removed in 2.0. */
|
|
891
|
+
export const UserSelectMenuBuilder = CreateUserSelectMenu;
|
|
892
|
+
/** @deprecated Use {@link CreateUserSelectMenu}. Removed in 2.0. */
|
|
893
|
+
export type UserSelectMenuBuilder = CreateUserSelectMenu;
|
|
894
|
+
|
|
895
|
+
/** @deprecated Use {@link CreateActionRow}. Removed in 2.0. */
|
|
896
|
+
export const ActionRowBuilder = CreateActionRow;
|
|
897
|
+
/** @deprecated Use {@link CreateActionRow}. Removed in 2.0. */
|
|
898
|
+
export type ActionRowBuilder<
|
|
899
|
+
T extends { toJSON(): APIActionRowChild } = { toJSON(): APIActionRowChild },
|
|
900
|
+
> = CreateActionRow<T>;
|
|
901
|
+
|
|
902
|
+
/** @deprecated Use {@link ButtonType}. Removed in 2.0. */
|
|
903
|
+
export const ButtonStyle = ButtonType;
|
|
904
|
+
/** @deprecated Use {@link ButtonType}. Removed in 2.0. */
|
|
905
|
+
export type ButtonStyle = ButtonType;
|
|
906
|
+
|
|
907
|
+
/** @deprecated Use {@link TextInputType}. Removed in 2.0. */
|
|
908
|
+
export const TextInputStyle = TextInputType;
|
|
909
|
+
/** @deprecated Use {@link TextInputType}. Removed in 2.0. */
|
|
910
|
+
export type TextInputStyle = TextInputType;
|
|
911
|
+
|
|
912
|
+
/** @deprecated Use {@link ComponentEnum}. Removed in 2.0. */
|
|
913
|
+
export const ComponentType = ComponentEnum;
|
|
914
|
+
/** @deprecated Use {@link ComponentEnum}. Removed in 2.0. */
|
|
915
|
+
export type ComponentType = ComponentEnum;
|
package/src/embed.ts
CHANGED
|
@@ -30,7 +30,7 @@ export interface APIEmbed {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
/** Builds compile-time-safe rich embed payloads for Discord API requests. */
|
|
33
|
-
export class
|
|
33
|
+
export class CreateEmbed {
|
|
34
34
|
readonly #data: APIEmbed = {};
|
|
35
35
|
/** Sets the embed title. @param value Title text, or null to clear. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */ public setTitle(
|
|
36
36
|
value: string | null,
|
|
@@ -203,3 +203,12 @@ function url(value: string, field: string): string {
|
|
|
203
203
|
throw new TypeError(`${field} must be a valid URL.`, { cause: error });
|
|
204
204
|
}
|
|
205
205
|
}
|
|
206
|
+
|
|
207
|
+
// ─── Deprecated names (0.2.2), removed in 2.0 ────────────────────────────────
|
|
208
|
+
// Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
|
|
209
|
+
// `…Type` and `…Type` became `…Enum`.
|
|
210
|
+
|
|
211
|
+
/** @deprecated Use {@link CreateEmbed}. Removed in 2.0. */
|
|
212
|
+
export const EmbedBuilder = CreateEmbed;
|
|
213
|
+
/** @deprecated Use {@link CreateEmbed}. Removed in 2.0. */
|
|
214
|
+
export type EmbedBuilder = CreateEmbed;
|