@lunibee/builders 0.2.3 → 0.3.0
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/package.json +2 -2
- package/src/attachment.ts +27 -11
- package/src/commands.ts +199 -324
- package/src/components.ts +30 -181
- package/src/embed.ts +66 -62
- package/src/index.ts +0 -47
package/src/components.ts
CHANGED
|
@@ -1,32 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { ButtonType } from "@lunibee/types";
|
|
4
|
-
export { ButtonType };
|
|
1
|
+
import { ButtonType, ComponentEnum } from "@lunibee/types";
|
|
2
|
+
export { ButtonType, ComponentEnum };
|
|
5
3
|
|
|
6
|
-
/** Component type constants exposed by Lunibee. */
|
|
7
|
-
export const ComponentEnum = {
|
|
8
|
-
ActionRow: 1,
|
|
9
|
-
Button: 2,
|
|
10
|
-
StringSelect: 3,
|
|
11
|
-
TextInput: 4,
|
|
12
|
-
UserSelect: 5,
|
|
13
|
-
RoleSelect: 6,
|
|
14
|
-
MentionableSelect: 7,
|
|
15
|
-
ChannelSelect: 8,
|
|
16
|
-
Section: 9,
|
|
17
|
-
TextDisplay: 10,
|
|
18
|
-
Thumbnail: 11,
|
|
19
|
-
MediaGallery: 12,
|
|
20
|
-
File: 13,
|
|
21
|
-
Separator: 14,
|
|
22
|
-
ContentInventoryEntry: 16,
|
|
23
|
-
Container: 17,
|
|
24
|
-
} as const;
|
|
25
4
|
export const TextInputType = { Short: 1, Paragraph: 2 } as const;
|
|
26
5
|
/** One {@link TextInputType} value, usable as a type. */
|
|
27
6
|
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];
|
|
30
7
|
export interface APIComponentEmoji {
|
|
31
8
|
id?: string | null;
|
|
32
9
|
name?: string | null;
|
|
@@ -197,38 +174,52 @@ export class CreateActionRow<
|
|
|
197
174
|
return { type: ComponentEnum.ActionRow, components };
|
|
198
175
|
}
|
|
199
176
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
177
|
+
/** Setters shared by string and entity select menus. */
|
|
178
|
+
export class CreateSelectMenu {
|
|
179
|
+
readonly #select: APIStringSelectComponent | APIEntitySelectComponent;
|
|
180
|
+
protected constructor(
|
|
181
|
+
data: APIStringSelectComponent | APIEntitySelectComponent,
|
|
182
|
+
) {
|
|
183
|
+
this.#select = data;
|
|
184
|
+
}
|
|
204
185
|
public setCustomId(value: string): this {
|
|
205
186
|
validateText(value, 100, "Component custom ID");
|
|
206
|
-
this.#
|
|
187
|
+
this.#select.custom_id = value;
|
|
207
188
|
return this;
|
|
208
189
|
}
|
|
209
190
|
public setPlaceholder(value: string): this {
|
|
210
191
|
validateText(value, 150, "Component placeholder");
|
|
211
|
-
this.#
|
|
192
|
+
this.#select.placeholder = value;
|
|
212
193
|
return this;
|
|
213
194
|
}
|
|
214
195
|
public setMinValues(value: number): this {
|
|
215
196
|
validateCount(value, "min_values", 0);
|
|
216
|
-
this.#
|
|
197
|
+
this.#select.min_values = value;
|
|
217
198
|
return this;
|
|
218
199
|
}
|
|
219
200
|
public setMaxValues(value: number): this {
|
|
220
201
|
validateCount(value, "max_values", 1);
|
|
221
|
-
this.#
|
|
202
|
+
this.#select.max_values = value;
|
|
222
203
|
return this;
|
|
223
204
|
}
|
|
224
205
|
public setRequired(value = true): this {
|
|
225
|
-
this.#
|
|
206
|
+
this.#select.required = value;
|
|
226
207
|
return this;
|
|
227
208
|
}
|
|
228
209
|
public setDisabled(value = true): this {
|
|
229
|
-
this.#
|
|
210
|
+
this.#select.disabled = value;
|
|
230
211
|
return this;
|
|
231
212
|
}
|
|
213
|
+
}
|
|
214
|
+
export class CreateStringSelect extends CreateSelectMenu {
|
|
215
|
+
readonly #data: APIStringSelectComponent;
|
|
216
|
+
public constructor() {
|
|
217
|
+
const data: APIStringSelectComponent = {
|
|
218
|
+
type: ComponentEnum.StringSelect,
|
|
219
|
+
};
|
|
220
|
+
super(data);
|
|
221
|
+
this.#data = data;
|
|
222
|
+
}
|
|
232
223
|
public addOptions(...options: APISelectOption[]): this {
|
|
233
224
|
if (!options.length)
|
|
234
225
|
throw new TypeError("At least one select option is required.");
|
|
@@ -358,7 +349,7 @@ export class CreateButton {
|
|
|
358
349
|
return structuredClone(data);
|
|
359
350
|
}
|
|
360
351
|
}
|
|
361
|
-
export class CreateEntitySelect {
|
|
352
|
+
export class CreateEntitySelect extends CreateSelectMenu {
|
|
362
353
|
readonly #data: APIEntitySelectComponent;
|
|
363
354
|
public constructor(
|
|
364
355
|
type:
|
|
@@ -374,35 +365,9 @@ export class CreateEntitySelect {
|
|
|
374
365
|
type !== ComponentEnum.ChannelSelect
|
|
375
366
|
)
|
|
376
367
|
throw new TypeError("Invalid select component type.");
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
validateText(value, 100, "Component custom ID");
|
|
381
|
-
this.#data.custom_id = value;
|
|
382
|
-
return this;
|
|
383
|
-
}
|
|
384
|
-
public setPlaceholder(value: string): this {
|
|
385
|
-
validateText(value, 150, "Component placeholder");
|
|
386
|
-
this.#data.placeholder = value;
|
|
387
|
-
return this;
|
|
388
|
-
}
|
|
389
|
-
public setMinValues(value: number): this {
|
|
390
|
-
validateCount(value, "min_values", 0);
|
|
391
|
-
this.#data.min_values = value;
|
|
392
|
-
return this;
|
|
393
|
-
}
|
|
394
|
-
public setMaxValues(value: number): this {
|
|
395
|
-
validateCount(value, "max_values", 1);
|
|
396
|
-
this.#data.max_values = value;
|
|
397
|
-
return this;
|
|
398
|
-
}
|
|
399
|
-
public setRequired(value = true): this {
|
|
400
|
-
this.#data.required = value;
|
|
401
|
-
return this;
|
|
402
|
-
}
|
|
403
|
-
public setDisabled(value = true): this {
|
|
404
|
-
this.#data.disabled = value;
|
|
405
|
-
return this;
|
|
368
|
+
const data: APIEntitySelectComponent = { type };
|
|
369
|
+
super(data);
|
|
370
|
+
this.#data = data;
|
|
406
371
|
}
|
|
407
372
|
public setDefaultValues(...values: APISelectDefaultValue[]): this {
|
|
408
373
|
this.#data.default_values = values.map((value) => ({ ...value }));
|
|
@@ -797,119 +762,3 @@ export function componentsV2Message<
|
|
|
797
762
|
flags: (options?.flags ?? 0) | IS_COMPONENTS_V2,
|
|
798
763
|
};
|
|
799
764
|
}
|
|
800
|
-
|
|
801
|
-
// ─── Deprecated names (0.2.2), removed in 0.3.0 ────────────────────────────────
|
|
802
|
-
// Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
|
|
803
|
-
// `…Type` and `…Type` became `…Enum`.
|
|
804
|
-
|
|
805
|
-
/** @deprecated Use {@link CreateButton}. Removed in 0.3.0. */
|
|
806
|
-
export const ButtonBuilder = CreateButton;
|
|
807
|
-
/** @deprecated Use {@link CreateButton}. Removed in 0.3.0. */
|
|
808
|
-
export type ButtonBuilder = CreateButton;
|
|
809
|
-
|
|
810
|
-
/** @deprecated Use {@link CreateChannelSelectMenu}. Removed in 0.3.0. */
|
|
811
|
-
export const ChannelSelectMenuBuilder = CreateChannelSelectMenu;
|
|
812
|
-
/** @deprecated Use {@link CreateChannelSelectMenu}. Removed in 0.3.0. */
|
|
813
|
-
export type ChannelSelectMenuBuilder = CreateChannelSelectMenu;
|
|
814
|
-
|
|
815
|
-
/** @deprecated Use {@link CreateContainer}. Removed in 0.3.0. */
|
|
816
|
-
export const ContainerBuilder = CreateContainer;
|
|
817
|
-
/** @deprecated Use {@link CreateContainer}. Removed in 0.3.0. */
|
|
818
|
-
export type ContainerBuilder = CreateContainer;
|
|
819
|
-
|
|
820
|
-
/** @deprecated Use {@link CreateContentInventoryEntry}. Removed in 0.3.0. */
|
|
821
|
-
export const ContentInventoryEntryBuilder = CreateContentInventoryEntry;
|
|
822
|
-
/** @deprecated Use {@link CreateContentInventoryEntry}. Removed in 0.3.0. */
|
|
823
|
-
export type ContentInventoryEntryBuilder = CreateContentInventoryEntry;
|
|
824
|
-
|
|
825
|
-
/** @deprecated Use {@link CreateEntitySelect}. Removed in 0.3.0. */
|
|
826
|
-
export const EntitySelectBuilder = CreateEntitySelect;
|
|
827
|
-
/** @deprecated Use {@link CreateEntitySelect}. Removed in 0.3.0. */
|
|
828
|
-
export type EntitySelectBuilder = CreateEntitySelect;
|
|
829
|
-
|
|
830
|
-
/** @deprecated Use {@link CreateFileComponent}. Removed in 0.3.0. */
|
|
831
|
-
export const FileComponentBuilder = CreateFileComponent;
|
|
832
|
-
/** @deprecated Use {@link CreateFileComponent}. Removed in 0.3.0. */
|
|
833
|
-
export type FileComponentBuilder = CreateFileComponent;
|
|
834
|
-
|
|
835
|
-
/** @deprecated Use {@link CreateMediaGallery}. Removed in 0.3.0. */
|
|
836
|
-
export const MediaGalleryBuilder = CreateMediaGallery;
|
|
837
|
-
/** @deprecated Use {@link CreateMediaGallery}. Removed in 0.3.0. */
|
|
838
|
-
export type MediaGalleryBuilder = CreateMediaGallery;
|
|
839
|
-
|
|
840
|
-
/** @deprecated Use {@link CreateMentionableSelectMenu}. Removed in 0.3.0. */
|
|
841
|
-
export const MentionableSelectMenuBuilder = CreateMentionableSelectMenu;
|
|
842
|
-
/** @deprecated Use {@link CreateMentionableSelectMenu}. Removed in 0.3.0. */
|
|
843
|
-
export type MentionableSelectMenuBuilder = CreateMentionableSelectMenu;
|
|
844
|
-
|
|
845
|
-
/** @deprecated Use {@link CreateModal}. Removed in 0.3.0. */
|
|
846
|
-
export const ModalBuilder = CreateModal;
|
|
847
|
-
/** @deprecated Use {@link CreateModal}. Removed in 0.3.0. */
|
|
848
|
-
export type ModalBuilder = CreateModal;
|
|
849
|
-
|
|
850
|
-
/** @deprecated Use {@link CreateRoleSelectMenu}. Removed in 0.3.0. */
|
|
851
|
-
export const RoleSelectMenuBuilder = CreateRoleSelectMenu;
|
|
852
|
-
/** @deprecated Use {@link CreateRoleSelectMenu}. Removed in 0.3.0. */
|
|
853
|
-
export type RoleSelectMenuBuilder = CreateRoleSelectMenu;
|
|
854
|
-
|
|
855
|
-
/** @deprecated Use {@link CreateSection}. Removed in 0.3.0. */
|
|
856
|
-
export const SectionBuilder = CreateSection;
|
|
857
|
-
/** @deprecated Use {@link CreateSection}. Removed in 0.3.0. */
|
|
858
|
-
export type SectionBuilder = CreateSection;
|
|
859
|
-
|
|
860
|
-
/** @deprecated Use {@link CreateSeparator}. Removed in 0.3.0. */
|
|
861
|
-
export const SeparatorBuilder = CreateSeparator;
|
|
862
|
-
/** @deprecated Use {@link CreateSeparator}. Removed in 0.3.0. */
|
|
863
|
-
export type SeparatorBuilder = CreateSeparator;
|
|
864
|
-
|
|
865
|
-
/** @deprecated Use {@link CreateStringSelect}. Removed in 0.3.0. */
|
|
866
|
-
export const StringSelectBuilder = CreateStringSelect;
|
|
867
|
-
/** @deprecated Use {@link CreateStringSelect}. Removed in 0.3.0. */
|
|
868
|
-
export type StringSelectBuilder = CreateStringSelect;
|
|
869
|
-
|
|
870
|
-
/** @deprecated Use {@link CreateStringSelectMenu}. Removed in 0.3.0. */
|
|
871
|
-
export const StringSelectMenuBuilder = CreateStringSelect;
|
|
872
|
-
/** @deprecated Use {@link CreateStringSelectMenu}. Removed in 0.3.0. */
|
|
873
|
-
export type StringSelectMenuBuilder = CreateStringSelect;
|
|
874
|
-
|
|
875
|
-
/** @deprecated Use {@link CreateTextDisplay}. Removed in 0.3.0. */
|
|
876
|
-
export const TextDisplayBuilder = CreateTextDisplay;
|
|
877
|
-
/** @deprecated Use {@link CreateTextDisplay}. Removed in 0.3.0. */
|
|
878
|
-
export type TextDisplayBuilder = CreateTextDisplay;
|
|
879
|
-
|
|
880
|
-
/** @deprecated Use {@link CreateTextInput}. Removed in 0.3.0. */
|
|
881
|
-
export const TextInputBuilder = CreateTextInput;
|
|
882
|
-
/** @deprecated Use {@link CreateTextInput}. Removed in 0.3.0. */
|
|
883
|
-
export type TextInputBuilder = CreateTextInput;
|
|
884
|
-
|
|
885
|
-
/** @deprecated Use {@link CreateThumbnail}. Removed in 0.3.0. */
|
|
886
|
-
export const ThumbnailBuilder = CreateThumbnail;
|
|
887
|
-
/** @deprecated Use {@link CreateThumbnail}. Removed in 0.3.0. */
|
|
888
|
-
export type ThumbnailBuilder = CreateThumbnail;
|
|
889
|
-
|
|
890
|
-
/** @deprecated Use {@link CreateUserSelectMenu}. Removed in 0.3.0. */
|
|
891
|
-
export const UserSelectMenuBuilder = CreateUserSelectMenu;
|
|
892
|
-
/** @deprecated Use {@link CreateUserSelectMenu}. Removed in 0.3.0. */
|
|
893
|
-
export type UserSelectMenuBuilder = CreateUserSelectMenu;
|
|
894
|
-
|
|
895
|
-
/** @deprecated Use {@link CreateActionRow}. Removed in 0.3.0. */
|
|
896
|
-
export const ActionRowBuilder = CreateActionRow;
|
|
897
|
-
/** @deprecated Use {@link CreateActionRow}. Removed in 0.3.0. */
|
|
898
|
-
export type ActionRowBuilder<
|
|
899
|
-
T extends { toJSON(): APIActionRowChild } = { toJSON(): APIActionRowChild },
|
|
900
|
-
> = CreateActionRow<T>;
|
|
901
|
-
|
|
902
|
-
/** @deprecated Use {@link ButtonType}. Removed in 0.3.0. */
|
|
903
|
-
export const ButtonStyle = ButtonType;
|
|
904
|
-
/** @deprecated Use {@link ButtonType}. Removed in 0.3.0. */
|
|
905
|
-
export type ButtonStyle = ButtonType;
|
|
906
|
-
|
|
907
|
-
/** @deprecated Use {@link TextInputType}. Removed in 0.3.0. */
|
|
908
|
-
export const TextInputStyle = TextInputType;
|
|
909
|
-
/** @deprecated Use {@link TextInputType}. Removed in 0.3.0. */
|
|
910
|
-
export type TextInputStyle = TextInputType;
|
|
911
|
-
|
|
912
|
-
/** @deprecated Use {@link ComponentEnum}. Removed in 0.3.0. */
|
|
913
|
-
export const ComponentType = ComponentEnum;
|
|
914
|
-
/** @deprecated Use {@link ComponentEnum}. Removed in 0.3.0. */
|
|
915
|
-
export type ComponentType = ComponentEnum;
|
package/src/embed.ts
CHANGED
|
@@ -1,62 +1,76 @@
|
|
|
1
1
|
/** Discord API embed field payload. */
|
|
2
2
|
export interface EmbedField {
|
|
3
|
-
/** Field name. */
|
|
4
|
-
|
|
5
|
-
/**
|
|
3
|
+
/** Field name. */
|
|
4
|
+
name: string;
|
|
5
|
+
/** Field value. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Whether the field is displayed inline. */
|
|
8
|
+
inline?: boolean;
|
|
6
9
|
}
|
|
7
10
|
/** Discord API embed footer payload. */
|
|
8
11
|
export interface EmbedFooter {
|
|
9
|
-
/** Footer text. */
|
|
10
|
-
|
|
12
|
+
/** Footer text. */
|
|
13
|
+
text: string;
|
|
14
|
+
/** Footer icon URL. */
|
|
15
|
+
icon_url?: string;
|
|
11
16
|
}
|
|
12
17
|
/** Discord API embed author payload. */
|
|
13
18
|
export interface EmbedAuthor {
|
|
14
|
-
/** Author display name. */
|
|
15
|
-
|
|
16
|
-
/** Author
|
|
19
|
+
/** Author display name. */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Author URL. */
|
|
22
|
+
url?: string;
|
|
23
|
+
/** Author icon URL. */
|
|
24
|
+
icon_url?: string;
|
|
17
25
|
}
|
|
18
26
|
/** Strict Discord API embed payload. */
|
|
19
27
|
export interface APIEmbed {
|
|
20
|
-
/** Embed title. */
|
|
21
|
-
|
|
22
|
-
/** Embed
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
|
|
26
|
-
/** Embed
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
|
|
28
|
+
/** Embed title. */
|
|
29
|
+
title?: string;
|
|
30
|
+
/** Embed description. */
|
|
31
|
+
description?: string;
|
|
32
|
+
/** Embed URL. */
|
|
33
|
+
url?: string;
|
|
34
|
+
/** Embed color. */
|
|
35
|
+
color?: number;
|
|
36
|
+
/** ISO-8601 timestamp. */
|
|
37
|
+
timestamp?: string;
|
|
38
|
+
/** Embed footer. */
|
|
39
|
+
footer?: EmbedFooter;
|
|
40
|
+
/** Embed author. */
|
|
41
|
+
author?: EmbedAuthor;
|
|
42
|
+
/** Thumbnail payload. */
|
|
43
|
+
thumbnail?: { /** Thumbnail URL. */ url: string };
|
|
44
|
+
/** Image payload. */
|
|
45
|
+
image?: { /** Image URL. */ url: string };
|
|
46
|
+
/** Embed fields. */
|
|
47
|
+
fields?: EmbedField[];
|
|
30
48
|
}
|
|
31
49
|
|
|
32
50
|
/** Builds compile-time-safe rich embed payloads for Discord API requests. */
|
|
33
51
|
export class CreateEmbed {
|
|
34
52
|
readonly #data: APIEmbed = {};
|
|
35
|
-
/** Sets the embed title. @param value Title text, or null to clear. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */
|
|
36
|
-
|
|
37
|
-
): this {
|
|
53
|
+
/** Sets the embed title. @param value Title text, or null to clear. @returns This builder. @throws {RangeError} If title exceeds Discord's limit. */
|
|
54
|
+
public setTitle(value: string | null): this {
|
|
38
55
|
if (value === null) delete this.#data.title;
|
|
39
56
|
else this.#data.title = validate(value, 256, "Embed title");
|
|
40
57
|
return this;
|
|
41
58
|
}
|
|
42
|
-
/** Sets the embed description. @param value Description text, or null to clear. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */
|
|
43
|
-
|
|
44
|
-
): this {
|
|
59
|
+
/** Sets the embed description. @param value Description text, or null to clear. @returns This builder. @throws {RangeError} If description exceeds Discord's limit. */
|
|
60
|
+
public setDescription(value: string | null): this {
|
|
45
61
|
if (value === null) delete this.#data.description;
|
|
46
62
|
else
|
|
47
63
|
this.#data.description = validate(value, 4096, "Embed description");
|
|
48
64
|
return this;
|
|
49
65
|
}
|
|
50
|
-
/** Sets the embed URL. @param value Absolute URL, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
51
|
-
|
|
52
|
-
): this {
|
|
66
|
+
/** Sets the embed URL. @param value Absolute URL, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
67
|
+
public setURL(value: string | null): this {
|
|
53
68
|
if (value === null) delete this.#data.url;
|
|
54
69
|
else this.#data.url = url(value, "Embed URL");
|
|
55
70
|
return this;
|
|
56
71
|
}
|
|
57
|
-
/** Sets the embed color. @param value RGB integer. @returns This builder. @throws {RangeError} If color is outside 24-bit RGB range. */
|
|
58
|
-
|
|
59
|
-
): this {
|
|
72
|
+
/** Sets the embed color. @param value RGB integer. @returns This builder. @throws {RangeError} If color is outside 24-bit RGB range. */
|
|
73
|
+
public setColor(value: number): this {
|
|
60
74
|
if (!Number.isInteger(value) || value < 0 || value > 0xffffff)
|
|
61
75
|
throw new RangeError(
|
|
62
76
|
"Embed color must be an integer between 0 and 16777215.",
|
|
@@ -64,18 +78,16 @@ export class CreateEmbed {
|
|
|
64
78
|
this.#data.color = value;
|
|
65
79
|
return this;
|
|
66
80
|
}
|
|
67
|
-
/** Sets the embed timestamp. @param value Date value. @returns This builder. @throws {RangeError} If date is invalid. */
|
|
68
|
-
|
|
69
|
-
): this {
|
|
81
|
+
/** Sets the embed timestamp. @param value Date value. @returns This builder. @throws {RangeError} If date is invalid. */
|
|
82
|
+
public setTimestamp(value = new Date()): this {
|
|
70
83
|
const date = value instanceof Date ? value : new Date(value);
|
|
71
84
|
if (Number.isNaN(date.getTime()))
|
|
72
85
|
throw new RangeError("Embed timestamp must be a valid date.");
|
|
73
86
|
this.#data.timestamp = date.toISOString();
|
|
74
87
|
return this;
|
|
75
88
|
}
|
|
76
|
-
/** Sets the embed footer. @param value Footer payload. @returns This builder. @throws {RangeError} If footer text exceeds Discord's limit. */
|
|
77
|
-
|
|
78
|
-
): this {
|
|
89
|
+
/** Sets the embed footer. @param value Footer payload. @returns This builder. @throws {RangeError} If footer text exceeds Discord's limit. */
|
|
90
|
+
public setFooter(value: EmbedFooter): this {
|
|
79
91
|
this.#data.footer = {
|
|
80
92
|
text: validate(value.text, 2048, "Footer text"),
|
|
81
93
|
...(value.icon_url
|
|
@@ -84,9 +96,8 @@ export class CreateEmbed {
|
|
|
84
96
|
};
|
|
85
97
|
return this;
|
|
86
98
|
}
|
|
87
|
-
/** Sets the embed author. @param value Author payload. @returns This builder. @throws {RangeError} If author name exceeds Discord's limit. */
|
|
88
|
-
|
|
89
|
-
): this {
|
|
99
|
+
/** Sets the embed author. @param value Author payload. @returns This builder. @throws {RangeError} If author name exceeds Discord's limit. */
|
|
100
|
+
public setAuthor(value: EmbedAuthor): this {
|
|
90
101
|
this.#data.author = {
|
|
91
102
|
name: validate(value.name, 256, "Author name"),
|
|
92
103
|
...(value.url ? { url: url(value.url, "Author URL") } : {}),
|
|
@@ -96,9 +107,8 @@ export class CreateEmbed {
|
|
|
96
107
|
};
|
|
97
108
|
return this;
|
|
98
109
|
}
|
|
99
|
-
/** Sets the thumbnail URL. @param value Thumbnail URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
100
|
-
|
|
101
|
-
): this {
|
|
110
|
+
/** Sets the thumbnail URL. @param value Thumbnail URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
111
|
+
public setThumbnail(value: { url: string } | string | null): this {
|
|
102
112
|
if (value === null) {
|
|
103
113
|
delete this.#data.thumbnail;
|
|
104
114
|
return this;
|
|
@@ -107,9 +117,8 @@ export class CreateEmbed {
|
|
|
107
117
|
this.#data.thumbnail = { url: url(valueURL, "Thumbnail URL") };
|
|
108
118
|
return this;
|
|
109
119
|
}
|
|
110
|
-
/** Sets the image URL. @param value Image URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
111
|
-
|
|
112
|
-
): this {
|
|
120
|
+
/** Sets the image URL. @param value Image URL or payload, or null to clear. @returns This builder. @throws {TypeError} If URL is invalid. */
|
|
121
|
+
public setImage(value: { url: string } | string | null): this {
|
|
113
122
|
if (value === null) {
|
|
114
123
|
delete this.#data.image;
|
|
115
124
|
return this;
|
|
@@ -120,9 +129,8 @@ export class CreateEmbed {
|
|
|
120
129
|
}
|
|
121
130
|
/** Adds embed fields. Accepts both the spread form `addFields(a, b)` and the
|
|
122
131
|
* single-array form `addFields([a, b])` for discord.js `RestOrArray` parity.
|
|
123
|
-
* @param fields Field payloads, spread or as a single array. @returns This builder. @throws {RangeError} If the 25-field limit is exceeded. */
|
|
124
|
-
|
|
125
|
-
): this {
|
|
132
|
+
* @param fields Field payloads, spread or as a single array. @returns This builder. @throws {RangeError} If the 25-field limit is exceeded. */
|
|
133
|
+
public addFields(...fields: EmbedField[] | [EmbedField[]]): this {
|
|
126
134
|
const resolved = (
|
|
127
135
|
fields.length === 1 && Array.isArray(fields[0]) ? fields[0] : fields
|
|
128
136
|
) as EmbedField[];
|
|
@@ -147,7 +155,8 @@ export class CreateEmbed {
|
|
|
147
155
|
this.#data.fields = [];
|
|
148
156
|
return this.addFields(...fields);
|
|
149
157
|
}
|
|
150
|
-
/** Replaces fields starting at an index. @param index Start index. @param deleteCount Number of fields to remove. @param fields Replacement fields. @returns This builder. @throws {RangeError} If arguments are invalid or the 25-field limit is exceeded. */
|
|
158
|
+
/** Replaces fields starting at an index. @param index Start index. @param deleteCount Number of fields to remove. @param fields Replacement fields. @returns This builder. @throws {RangeError} If arguments are invalid or the 25-field limit is exceeded. */
|
|
159
|
+
public spliceFields(
|
|
151
160
|
index: number,
|
|
152
161
|
deleteCount: number,
|
|
153
162
|
...fields: EmbedField[]
|
|
@@ -170,19 +179,23 @@ export class CreateEmbed {
|
|
|
170
179
|
this.#data.fields = current;
|
|
171
180
|
return this;
|
|
172
181
|
}
|
|
173
|
-
/** Removes all embed fields. @returns This builder. */
|
|
182
|
+
/** Removes all embed fields. @returns This builder. */
|
|
183
|
+
public clearFields(): this {
|
|
174
184
|
delete this.#data.fields;
|
|
175
185
|
return this;
|
|
176
186
|
}
|
|
177
|
-
/** Removes the embed title. @returns This builder. */
|
|
187
|
+
/** Removes the embed title. @returns This builder. */
|
|
188
|
+
public clearTitle(): this {
|
|
178
189
|
delete this.#data.title;
|
|
179
190
|
return this;
|
|
180
191
|
}
|
|
181
|
-
/** Removes the embed description. @returns This builder. */
|
|
192
|
+
/** Removes the embed description. @returns This builder. */
|
|
193
|
+
public clearDescription(): this {
|
|
182
194
|
delete this.#data.description;
|
|
183
195
|
return this;
|
|
184
196
|
}
|
|
185
|
-
/** Returns a deep-cloned Discord API payload. @returns Strict embed payload. */
|
|
197
|
+
/** Returns a deep-cloned Discord API payload. @returns Strict embed payload. */
|
|
198
|
+
public get data(): APIEmbed {
|
|
186
199
|
return this.toJSON();
|
|
187
200
|
}
|
|
188
201
|
public toJSON(): APIEmbed {
|
|
@@ -203,12 +216,3 @@ function url(value: string, field: string): string {
|
|
|
203
216
|
throw new TypeError(`${field} must be a valid URL.`, { cause: error });
|
|
204
217
|
}
|
|
205
218
|
}
|
|
206
|
-
|
|
207
|
-
// ─── Deprecated names (0.2.2), removed in 0.3.0 ────────────────────────────────
|
|
208
|
-
// Builders are now `CreateX` (`ButtonBuilder` → `CreateButton`); `…Style` became
|
|
209
|
-
// `…Type` and `…Type` became `…Enum`.
|
|
210
|
-
|
|
211
|
-
/** @deprecated Use {@link CreateEmbed}. Removed in 0.3.0. */
|
|
212
|
-
export const EmbedBuilder = CreateEmbed;
|
|
213
|
-
/** @deprecated Use {@link CreateEmbed}. Removed in 0.3.0. */
|
|
214
|
-
export type EmbedBuilder = CreateEmbed;
|
package/src/index.ts
CHANGED
|
@@ -45,53 +45,6 @@ export {
|
|
|
45
45
|
CreateContextMenuCommand,
|
|
46
46
|
} from "./commands.js";
|
|
47
47
|
export { CreateAttachment, type AttachmentData } from "./attachment.js";
|
|
48
|
-
|
|
49
|
-
// Deprecated names (0.2.2), removed in 0.3.0.
|
|
50
|
-
export { AttachmentBuilder } from "./attachment.js";
|
|
51
|
-
export { EmbedBuilder } from "./embed.js";
|
|
52
|
-
export {
|
|
53
|
-
AttachmentOptionBuilder,
|
|
54
|
-
BooleanOptionBuilder,
|
|
55
|
-
ChannelOptionBuilder,
|
|
56
|
-
CommandOptionBuilder,
|
|
57
|
-
ContextMenuCommandBuilder,
|
|
58
|
-
IntegerOptionBuilder,
|
|
59
|
-
MentionableOptionBuilder,
|
|
60
|
-
MessageCommandBuilder,
|
|
61
|
-
NumberOptionBuilder,
|
|
62
|
-
RoleOptionBuilder,
|
|
63
|
-
SlashCommandBuilder,
|
|
64
|
-
StringOptionBuilder,
|
|
65
|
-
SubcommandBuilder,
|
|
66
|
-
SubcommandGroupBuilder,
|
|
67
|
-
UserCommandBuilder,
|
|
68
|
-
UserOptionBuilder,
|
|
69
|
-
ApplicationCommandOptionType,
|
|
70
|
-
} from "./commands.js";
|
|
71
|
-
export {
|
|
72
|
-
ButtonBuilder,
|
|
73
|
-
ChannelSelectMenuBuilder,
|
|
74
|
-
ContainerBuilder,
|
|
75
|
-
ContentInventoryEntryBuilder,
|
|
76
|
-
EntitySelectBuilder,
|
|
77
|
-
FileComponentBuilder,
|
|
78
|
-
MediaGalleryBuilder,
|
|
79
|
-
MentionableSelectMenuBuilder,
|
|
80
|
-
ModalBuilder,
|
|
81
|
-
RoleSelectMenuBuilder,
|
|
82
|
-
SectionBuilder,
|
|
83
|
-
SeparatorBuilder,
|
|
84
|
-
StringSelectBuilder,
|
|
85
|
-
StringSelectMenuBuilder,
|
|
86
|
-
TextDisplayBuilder,
|
|
87
|
-
TextInputBuilder,
|
|
88
|
-
ThumbnailBuilder,
|
|
89
|
-
UserSelectMenuBuilder,
|
|
90
|
-
ActionRowBuilder,
|
|
91
|
-
ButtonStyle,
|
|
92
|
-
TextInputStyle,
|
|
93
|
-
ComponentType,
|
|
94
|
-
} from "./components.js";
|
|
95
48
|
export type {
|
|
96
49
|
APIComponent,
|
|
97
50
|
APIComponentEmoji,
|