mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(Embed): Add all the types (#8254)
This commit is contained in:
@@ -6,14 +6,9 @@ const isEqual = require('fast-deep-equal');
|
||||
* Represents an embed.
|
||||
*/
|
||||
class Embed {
|
||||
/**
|
||||
* Creates a new embed object
|
||||
* @param {APIEmbed} data API embed data
|
||||
* @private
|
||||
*/
|
||||
constructor(data) {
|
||||
/**
|
||||
* The API embed data
|
||||
* The API embed data.
|
||||
* @type {APIEmbed}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -21,16 +16,16 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* An array of fields of this embed
|
||||
* @type {?Array<APIEmbedField>}
|
||||
* An array of fields of this embed.
|
||||
* @type {Array<APIEmbedField>}
|
||||
* @readonly
|
||||
*/
|
||||
get fields() {
|
||||
return this.data.fields ?? null;
|
||||
return this.data.fields ?? [];
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed title
|
||||
* The title of this embed.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -39,7 +34,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed description
|
||||
* The description of this embed.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -48,7 +43,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed URL
|
||||
* The URL of this embed.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -57,7 +52,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed color
|
||||
* The color of this embed.
|
||||
* @type {?number}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -66,7 +61,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The timestamp of the embed in an ISO 8601 format
|
||||
* The timestamp of this embed. This is in an ISO 8601 format.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -75,8 +70,16 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed thumbnail data
|
||||
* @type {?EmbedImageData}
|
||||
* @typedef {Object} EmbedAssetData
|
||||
* @property {?string} url The URL of the image
|
||||
* @property {?string} proxyURL The proxy URL of the image
|
||||
* @property {?string} height The height of the image
|
||||
* @property {?string} width The width of the image
|
||||
*/
|
||||
|
||||
/**
|
||||
* The thumbnail of this embed.
|
||||
* @type {?EmbedAssetData}
|
||||
* @readonly
|
||||
*/
|
||||
get thumbnail() {
|
||||
@@ -90,8 +93,8 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed image data
|
||||
* @type {?EmbedImageData}
|
||||
* The image of this embed.
|
||||
* @type {?EmbedAssetData}
|
||||
* @readonly
|
||||
*/
|
||||
get image() {
|
||||
@@ -105,16 +108,30 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* Received video data
|
||||
* @type {?EmbedVideoData}
|
||||
* The video of this embed.
|
||||
* @type {?EmbedAssetData}
|
||||
* @readonly
|
||||
*/
|
||||
get video() {
|
||||
return this.data.video ?? null;
|
||||
if (!this.data.video) return null;
|
||||
return {
|
||||
url: this.data.image.url,
|
||||
proxyURL: this.data.image.proxy_url,
|
||||
height: this.data.image.height,
|
||||
width: this.data.image.width,
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed author data
|
||||
* @typedef {Object} EmbedAuthorData
|
||||
* @property {string} name The name of the author
|
||||
* @property {?string} url The URL of the author
|
||||
* @property {?string} iconURL The icon URL of the author
|
||||
* @property {?string} proxyIconURL The proxy icon URL of the author
|
||||
*/
|
||||
|
||||
/**
|
||||
* The author of this embed.
|
||||
* @type {?EmbedAuthorData}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -129,8 +146,8 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* Received data about the embed provider
|
||||
* @type {?EmbedProvider}
|
||||
* The provider of this embed.
|
||||
* @type {?APIEmbedProvider}
|
||||
* @readonly
|
||||
*/
|
||||
get provider() {
|
||||
@@ -138,7 +155,14 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The embed footer data
|
||||
* @typedef {Object} EmbedFooterData
|
||||
* @property {string} text The text of the footer
|
||||
* @property {?string} iconURL The URL of the icon
|
||||
* @property {?string} proxyIconURL The proxy URL of the icon
|
||||
*/
|
||||
|
||||
/**
|
||||
* The footer of this embed.
|
||||
* @type {?EmbedFooterData}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -152,7 +176,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The accumulated length for the embed title, description, fields, footer text, and author name
|
||||
* The accumulated length for the embed title, description, fields, footer text, and author name.
|
||||
* @type {number}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -167,7 +191,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* The hex color of the current color of the embed
|
||||
* The hex color of this embed.
|
||||
* @type {?string}
|
||||
* @readonly
|
||||
*/
|
||||
@@ -178,7 +202,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the API-compatible JSON for this embed
|
||||
* Returns the API-compatible JSON for this embed.
|
||||
* @returns {APIEmbed}
|
||||
*/
|
||||
toJSON() {
|
||||
@@ -186,7 +210,7 @@ class Embed {
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether or not the given embeds are equal
|
||||
* Whether the given embeds are equal.
|
||||
* @param {Embed|APIEmbed} other The embed to compare against
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
@@ -48,6 +48,11 @@
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedField}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external APIEmbedProvider
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmbedProvider}
|
||||
*/
|
||||
|
||||
/**
|
||||
* @external APIEmoji
|
||||
* @see {@link https://discord-api-types.dev/api/discord-api-types-v10/interface/APIEmoji}
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedData
|
||||
* @property {?string} title The title of the embed
|
||||
* @property {?EmbedType} type The type of the embed
|
||||
* @property {?string} description The description of the embed
|
||||
* @property {?string} url The URL of the embed
|
||||
* @property {?string} timestamp The timestamp on the embed
|
||||
* @property {?number} color The color of the embed
|
||||
* @property {?EmbedFooterData} footer The footer of the embed
|
||||
* @property {?EmbedImageData} image The image of the embed
|
||||
* @property {?EmbedImageData} thumbnail The thumbnail of the embed
|
||||
* @property {?EmbedProviderData} provider The provider of the embed
|
||||
* @property {?EmbedAuthorData} author The author in the embed
|
||||
* @property {?EmbedFieldData[]} fields The fields in this embed
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedFooterData
|
||||
* @property {string} text The text of the footer
|
||||
* @property {?string} iconURL The URL of the icon
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedImageData
|
||||
* @property {?string} url The URL of the image
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedProviderData
|
||||
* @property {?string} name The name of the provider
|
||||
* @property {?string} url The URL of the provider
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedAuthorData
|
||||
* @property {string} name The name of the author
|
||||
* @property {?string} url The URL of the author
|
||||
* @property {?string} iconURL The icon URL of the author
|
||||
*/
|
||||
|
||||
/**
|
||||
* @typedef {Object} EmbedFieldData
|
||||
* @property {string} name The name of the field
|
||||
* @property {string} value The value of the field
|
||||
* @property {?boolean} inline Whether to inline this field
|
||||
*/
|
||||
39
packages/discord.js/typings/index.d.ts
vendored
39
packages/discord.js/typings/index.d.ts
vendored
@@ -113,7 +113,6 @@ import {
|
||||
APIEmbedAuthor,
|
||||
APIEmbedFooter,
|
||||
APIEmbedImage,
|
||||
APIEmbedVideo,
|
||||
VideoQualityMode,
|
||||
LocalizationMap,
|
||||
LocaleString,
|
||||
@@ -122,6 +121,7 @@ import {
|
||||
APIChannel,
|
||||
ThreadAutoArchiveDuration,
|
||||
FormattingPatterns,
|
||||
APIEmbedProvider,
|
||||
} from 'discord-api-types/v10';
|
||||
import { ChildProcess } from 'node:child_process';
|
||||
import { EventEmitter } from 'node:events';
|
||||
@@ -667,12 +667,12 @@ export interface EmbedData {
|
||||
timestamp?: string | number | Date;
|
||||
color?: number;
|
||||
footer?: EmbedFooterData;
|
||||
image?: EmbedImageData;
|
||||
thumbnail?: EmbedImageData;
|
||||
provider?: EmbedProviderData;
|
||||
image?: EmbedAssetData;
|
||||
thumbnail?: EmbedAssetData;
|
||||
provider?: APIEmbedProvider;
|
||||
author?: EmbedAuthorData;
|
||||
fields?: EmbedFieldData[];
|
||||
video?: EmbedVideoData;
|
||||
fields?: APIEmbedField[];
|
||||
video?: EmbedAssetData;
|
||||
}
|
||||
|
||||
export interface IconData {
|
||||
@@ -684,16 +684,7 @@ export type EmbedAuthorData = Omit<APIEmbedAuthor, 'icon_url' | 'proxy_icon_url'
|
||||
|
||||
export type EmbedFooterData = Omit<APIEmbedFooter, 'icon_url' | 'proxy_icon_url'> & IconData;
|
||||
|
||||
export interface EmbedProviderData {
|
||||
name?: string;
|
||||
url?: string;
|
||||
}
|
||||
|
||||
export interface EmbedImageData extends Omit<APIEmbedImage, 'proxy_url'> {
|
||||
proxyURL?: string;
|
||||
}
|
||||
|
||||
export interface EmbedVideoData extends Omit<APIEmbedVideo, 'proxy_url'> {
|
||||
export interface EmbedAssetData extends Omit<APIEmbedImage, 'proxy_url'> {
|
||||
proxyURL?: string;
|
||||
}
|
||||
|
||||
@@ -706,7 +697,7 @@ export class EmbedBuilder extends BuildersEmbed {
|
||||
export class Embed {
|
||||
private constructor(data: APIEmbed);
|
||||
public readonly data: Readonly<APIEmbed>;
|
||||
public get fields(): APIEmbedField[] | null;
|
||||
public get fields(): APIEmbedField[];
|
||||
public get footer(): EmbedFooterData | null;
|
||||
public get title(): string | null;
|
||||
public get description(): string | null;
|
||||
@@ -714,11 +705,11 @@ export class Embed {
|
||||
public get color(): number | null;
|
||||
public get hexColor(): string | null;
|
||||
public get timestamp(): string | null;
|
||||
public get thumbnail(): EmbedImageData | null;
|
||||
public get image(): EmbedImageData | null;
|
||||
public get thumbnail(): EmbedAssetData | null;
|
||||
public get image(): EmbedAssetData | null;
|
||||
public get author(): EmbedAuthorData | null;
|
||||
public get provider(): EmbedProviderData | null;
|
||||
public get video(): EmbedVideoData | null;
|
||||
public get provider(): APIEmbedProvider | null;
|
||||
public get video(): EmbedAssetData | null;
|
||||
public get length(): number;
|
||||
public equals(other: Embed | APIEmbed): boolean;
|
||||
public toJSON(): APIEmbed;
|
||||
@@ -4413,12 +4404,6 @@ export interface EmbedField {
|
||||
inline: boolean;
|
||||
}
|
||||
|
||||
export interface EmbedFieldData {
|
||||
name: string;
|
||||
value: string;
|
||||
inline?: boolean;
|
||||
}
|
||||
|
||||
export type EmojiIdentifierResolvable = string | EmojiResolvable;
|
||||
|
||||
export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;
|
||||
|
||||
Reference in New Issue
Block a user