mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
feat(MessageEmbed): add #equals (#6885)
This commit is contained in:
@@ -263,6 +263,56 @@ class MessageEmbed {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this embed is equal to another one by comparing every single one of their properties.
|
||||||
|
* @param {MessageEmbed|APIEmbed} embed The embed to compare with
|
||||||
|
* @returns {boolean}
|
||||||
|
*/
|
||||||
|
equals(embed) {
|
||||||
|
return (
|
||||||
|
this.type === embed.type &&
|
||||||
|
this.author?.name === embed.author?.name &&
|
||||||
|
this.author?.url === embed.author?.url &&
|
||||||
|
this.author?.iconURL === (embed.author?.iconURL ?? embed.author?.icon_url) &&
|
||||||
|
this.author?.proxyIconURL === (embed.author?.proxyIconURL ?? embed.author?.proxy_icon_url) &&
|
||||||
|
this.color === embed.color &&
|
||||||
|
this.title === embed.title &&
|
||||||
|
this.description === embed.description &&
|
||||||
|
this.url === embed.url &&
|
||||||
|
this.timestamp === embed.timestamp &&
|
||||||
|
this.fields.length === embed.fields.length &&
|
||||||
|
this.fields.every((field, i) => this._fieldEquals(field, embed.fields[i])) &&
|
||||||
|
this.footer?.text === embed.footer?.text &&
|
||||||
|
this.footer?.iconURL === (embed.footer?.iconURL ?? embed.footer?.icon_url) &&
|
||||||
|
this.footer?.proxyIconURL === (embed.footer?.proxyIconURL ?? embed.footer?.proxy_icon_url) &&
|
||||||
|
this.image?.url === embed.image?.url &&
|
||||||
|
this.image?.proxyURL === (embed.image?.proxyURL ?? embed.image?.proxy_url) &&
|
||||||
|
this.image?.height === embed.image?.height &&
|
||||||
|
this.image?.width === embed.image?.width &&
|
||||||
|
this.thumbnail?.url === embed.thumbnail?.url &&
|
||||||
|
this.thumbnail?.proxyURL === (embed.thumbnail?.proxyURL ?? embed.thumbnail?.proxy_url) &&
|
||||||
|
this.thumbnail?.height === embed.thumbnail?.height &&
|
||||||
|
this.thumbnail?.width === embed.thumbnail?.width &&
|
||||||
|
this.video?.url === embed.video?.url &&
|
||||||
|
this.video?.proxyURL === (embed.video?.proxyURL ?? embed.video?.proxy_url) &&
|
||||||
|
this.video?.height === embed.video?.height &&
|
||||||
|
this.video?.width === embed.video?.width &&
|
||||||
|
this.provider?.name === embed.provider?.name &&
|
||||||
|
this.provider?.url === embed.provider?.url
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compares two given embed fields to see if they are equal
|
||||||
|
* @param {EmbedFieldData} field The first field to compare
|
||||||
|
* @param {EmbedFieldData} other The second field to compare
|
||||||
|
* @returns {boolean}
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
_fieldEquals(field, other) {
|
||||||
|
return field.name === other.name && field.value === other.value && field.inline === other.inline;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a field to the embed (max 25).
|
* Adds a field to the embed (max 25).
|
||||||
* @param {string} name The name of this field
|
* @param {string} name The name of this field
|
||||||
|
|||||||
3
typings/index.d.ts
vendored
3
typings/index.d.ts
vendored
@@ -1428,6 +1428,8 @@ export class MessageComponentInteraction<Cached extends CacheType = CacheType> e
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class MessageEmbed {
|
export class MessageEmbed {
|
||||||
|
private _fieldEquals(field: EmbedField, other: EmbedField): boolean;
|
||||||
|
|
||||||
public constructor(data?: MessageEmbed | MessageEmbedOptions | APIEmbed);
|
public constructor(data?: MessageEmbed | MessageEmbedOptions | APIEmbed);
|
||||||
public author: MessageEmbedAuthor | null;
|
public author: MessageEmbedAuthor | null;
|
||||||
public color: number | null;
|
public color: number | null;
|
||||||
@@ -1459,6 +1461,7 @@ export class MessageEmbed {
|
|||||||
public setTitle(title: string): this;
|
public setTitle(title: string): this;
|
||||||
public setURL(url: string): this;
|
public setURL(url: string): this;
|
||||||
public spliceFields(index: number, deleteCount: number, ...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
|
public spliceFields(index: number, deleteCount: number, ...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
|
||||||
|
public equals(embed: MessageEmbed | APIEmbed): boolean;
|
||||||
public toJSON(): unknown;
|
public toJSON(): unknown;
|
||||||
|
|
||||||
public static normalizeField(name: string, value: string, inline?: boolean): Required<EmbedFieldData>;
|
public static normalizeField(name: string, value: string, inline?: boolean): Required<EmbedFieldData>;
|
||||||
|
|||||||
Reference in New Issue
Block a user