Skip to content

Commit 890b1be

Browse files
authored
feat(RichEmbed): add length getter (#3057)
1 parent a2a0c05 commit 890b1be

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/structures/RichEmbed.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,21 @@ class RichEmbed {
235235
return this;
236236
}
237237

238+
/**
239+
* The accumulated length for the embed title, description, fields, author and footer text
240+
* @type {number}
241+
* @readonly
242+
*/
243+
get length() {
244+
return (
245+
(this.title ? this.title.length : 0) +
246+
(this.description ? this.description.length : 0) +
247+
(this.fields.length >= 1 ? this.fields.reduce((prev, curr) =>
248+
prev + curr.name.length + curr.value.length, 0) : 0) +
249+
(this.footer ? this.footer.text.length : 0) +
250+
(this.author ? this.author.name.length : 0));
251+
}
252+
238253
/**
239254
* Transforms the embed object to be processed.
240255
* @returns {Object} The raw data of this embed

typings/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,6 +1015,7 @@ declare module 'discord.js' {
10151015
public files?: Array<Attachment | string | FileOptions>;
10161016
public footer?: { text?: string; icon_url?: string; };
10171017
public image?: { url: string; proxy_url?: string; height?: number; width?: number; };
1018+
public readonly length: number;
10181019
public thumbnail?: { url: string; height?: number; width?: number; };
10191020
public timestamp?: Date;
10201021
public title?: string;

0 commit comments

Comments
 (0)