Skip to content

Commit 64f8140

Browse files
authored
refactor(Embed): Add all the types (#8254)
1 parent 33a7a5c commit 64f8140

File tree

4 files changed

+70
-104
lines changed

4 files changed

+70
-104
lines changed

Diff for: packages/discord.js/src/structures/Embed.js

+53-29
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,26 @@ const isEqual = require('fast-deep-equal');
66
* Represents an embed.
77
*/
88
class Embed {
9-
/**
10-
* Creates a new embed object
11-
* @param {APIEmbed} data API embed data
12-
* @private
13-
*/
149
constructor(data) {
1510
/**
16-
* The API embed data
11+
* The API embed data.
1712
* @type {APIEmbed}
1813
* @readonly
1914
*/
2015
this.data = { ...data };
2116
}
2217

2318
/**
24-
* An array of fields of this embed
25-
* @type {?Array<APIEmbedField>}
19+
* An array of fields of this embed.
20+
* @type {Array<APIEmbedField>}
2621
* @readonly
2722
*/
2823
get fields() {
29-
return this.data.fields ?? null;
24+
return this.data.fields ?? [];
3025
}
3126

3227
/**
33-
* The embed title
28+
* The title of this embed.
3429
* @type {?string}
3530
* @readonly
3631
*/
@@ -39,7 +34,7 @@ class Embed {
3934
}
4035

4136
/**
42-
* The embed description
37+
* The description of this embed.
4338
* @type {?string}
4439
* @readonly
4540
*/
@@ -48,7 +43,7 @@ class Embed {
4843
}
4944

5045
/**
51-
* The embed URL
46+
* The URL of this embed.
5247
* @type {?string}
5348
* @readonly
5449
*/
@@ -57,7 +52,7 @@ class Embed {
5752
}
5853

5954
/**
60-
* The embed color
55+
* The color of this embed.
6156
* @type {?number}
6257
* @readonly
6358
*/
@@ -66,7 +61,7 @@ class Embed {
6661
}
6762

6863
/**
69-
* The timestamp of the embed in an ISO 8601 format
64+
* The timestamp of this embed. This is in an ISO 8601 format.
7065
* @type {?string}
7166
* @readonly
7267
*/
@@ -75,8 +70,16 @@ class Embed {
7570
}
7671

7772
/**
78-
* The embed thumbnail data
79-
* @type {?EmbedImageData}
73+
* @typedef {Object} EmbedAssetData
74+
* @property {?string} url The URL of the image
75+
* @property {?string} proxyURL The proxy URL of the image
76+
* @property {?string} height The height of the image
77+
* @property {?string} width The width of the image
78+
*/
79+
80+
/**
81+
* The thumbnail of this embed.
82+
* @type {?EmbedAssetData}
8083
* @readonly
8184
*/
8285
get thumbnail() {
@@ -90,8 +93,8 @@ class Embed {
9093
}
9194

9295
/**
93-
* The embed image data
94-
* @type {?EmbedImageData}
96+
* The image of this embed.
97+
* @type {?EmbedAssetData}
9598
* @readonly
9699
*/
97100
get image() {
@@ -105,16 +108,30 @@ class Embed {
105108
}
106109

107110
/**
108-
* Received video data
109-
* @type {?EmbedVideoData}
111+
* The video of this embed.
112+
* @type {?EmbedAssetData}
110113
* @readonly
111114
*/
112115
get video() {
113-
return this.data.video ?? null;
116+
if (!this.data.video) return null;
117+
return {
118+
url: this.data.image.url,
119+
proxyURL: this.data.image.proxy_url,
120+
height: this.data.image.height,
121+
width: this.data.image.width,
122+
};
114123
}
115124

116125
/**
117-
* The embed author data
126+
* @typedef {Object} EmbedAuthorData
127+
* @property {string} name The name of the author
128+
* @property {?string} url The URL of the author
129+
* @property {?string} iconURL The icon URL of the author
130+
* @property {?string} proxyIconURL The proxy icon URL of the author
131+
*/
132+
133+
/**
134+
* The author of this embed.
118135
* @type {?EmbedAuthorData}
119136
* @readonly
120137
*/
@@ -129,16 +146,23 @@ class Embed {
129146
}
130147

131148
/**
132-
* Received data about the embed provider
133-
* @type {?EmbedProvider}
149+
* The provider of this embed.
150+
* @type {?APIEmbedProvider}
134151
* @readonly
135152
*/
136153
get provider() {
137154
return this.data.provider ?? null;
138155
}
139156

140157
/**
141-
* The embed footer data
158+
* @typedef {Object} EmbedFooterData
159+
* @property {string} text The text of the footer
160+
* @property {?string} iconURL The URL of the icon
161+
* @property {?string} proxyIconURL The proxy URL of the icon
162+
*/
163+
164+
/**
165+
* The footer of this embed.
142166
* @type {?EmbedFooterData}
143167
* @readonly
144168
*/
@@ -152,7 +176,7 @@ class Embed {
152176
}
153177

154178
/**
155-
* The accumulated length for the embed title, description, fields, footer text, and author name
179+
* The accumulated length for the embed title, description, fields, footer text, and author name.
156180
* @type {number}
157181
* @readonly
158182
*/
@@ -167,7 +191,7 @@ class Embed {
167191
}
168192

169193
/**
170-
* The hex color of the current color of the embed
194+
* The hex color of this embed.
171195
* @type {?string}
172196
* @readonly
173197
*/
@@ -178,15 +202,15 @@ class Embed {
178202
}
179203

180204
/**
181-
* Returns the API-compatible JSON for this embed
205+
* Returns the API-compatible JSON for this embed.
182206
* @returns {APIEmbed}
183207
*/
184208
toJSON() {
185209
return { ...this.data };
186210
}
187211

188212
/**
189-
* Whether or not the given embeds are equal
213+
* Whether the given embeds are equal.
190214
* @param {Embed|APIEmbed} other The embed to compare against
191215
* @returns {boolean}
192216
*/

Diff for: packages/discord.js/src/util/APITypes.js

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@
4848
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedField}
4949
*/
5050

51+
/**
52+
* @external APIEmbedProvider
53+
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedProvider}
54+
*/
55+
5156
/**
5257
* @external APIEmoji
5358
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmoji}

Diff for: packages/discord.js/src/util/Embeds.js

-48
This file was deleted.

Diff for: packages/discord.js/typings/index.d.ts

+12-27
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ import {
113113
APIEmbedAuthor,
114114
APIEmbedFooter,
115115
APIEmbedImage,
116-
APIEmbedVideo,
117116
VideoQualityMode,
118117
LocalizationMap,
119118
LocaleString,
@@ -122,6 +121,7 @@ import {
122121
APIChannel,
123122
ThreadAutoArchiveDuration,
124123
FormattingPatterns,
124+
APIEmbedProvider,
125125
} from 'discord-api-types/v10';
126126
import { ChildProcess } from 'node:child_process';
127127
import { EventEmitter } from 'node:events';
@@ -667,12 +667,12 @@ export interface EmbedData {
667667
timestamp?: string | number | Date;
668668
color?: number;
669669
footer?: EmbedFooterData;
670-
image?: EmbedImageData;
671-
thumbnail?: EmbedImageData;
672-
provider?: EmbedProviderData;
670+
image?: EmbedAssetData;
671+
thumbnail?: EmbedAssetData;
672+
provider?: APIEmbedProvider;
673673
author?: EmbedAuthorData;
674-
fields?: EmbedFieldData[];
675-
video?: EmbedVideoData;
674+
fields?: APIEmbedField[];
675+
video?: EmbedAssetData;
676676
}
677677

678678
export interface IconData {
@@ -684,16 +684,7 @@ export type EmbedAuthorData = Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'
684684

685685
export type EmbedFooterData = Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'> & IconData;
686686

687-
export interface EmbedProviderData {
688-
name?: string;
689-
url?: string;
690-
}
691-
692-
export interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {
693-
proxyURL?: string;
694-
}
695-
696-
export interface EmbedVideoData extends Omit<APIEmbedVideo, 'proxy_url'> {
687+
export interface EmbedAssetData extends Omit<APIEmbedImage, 'proxy_url'> {
697688
proxyURL?: string;
698689
}
699690

@@ -706,19 +697,19 @@ export class EmbedBuilder extends BuildersEmbed {
706697
export class Embed {
707698
private constructor(data: APIEmbed);
708699
public readonly data: Readonly<APIEmbed>;
709-
public get fields(): APIEmbedField[] | null;
700+
public get fields(): APIEmbedField[];
710701
public get footer(): EmbedFooterData | null;
711702
public get title(): string | null;
712703
public get description(): string | null;
713704
public get url(): string | null;
714705
public get color(): number | null;
715706
public get hexColor(): string | null;
716707
public get timestamp(): string | null;
717-
public get thumbnail(): EmbedImageData | null;
718-
public get image(): EmbedImageData | null;
708+
public get thumbnail(): EmbedAssetData | null;
709+
public get image(): EmbedAssetData | null;
719710
public get author(): EmbedAuthorData | null;
720-
public get provider(): EmbedProviderData | null;
721-
public get video(): EmbedVideoData | null;
711+
public get provider(): APIEmbedProvider | null;
712+
public get video(): EmbedAssetData | null;
722713
public get length(): number;
723714
public equals(other: Embed | APIEmbed): boolean;
724715
public toJSON(): APIEmbed;
@@ -4413,12 +4404,6 @@ export interface EmbedField {
44134404
inline: boolean;
44144405
}
44154406

4416-
export interface EmbedFieldData {
4417-
name: string;
4418-
value: string;
4419-
inline?: boolean;
4420-
}
4421-
44224407
export type EmojiIdentifierResolvable = string | EmojiResolvable;
44234408

44244409
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;

0 commit comments

Comments
 (0)