diff --git a/src/structures/MessageEmbed.js b/src/structures/MessageEmbed.js index 213a27a1d..0c925d276 100644 --- a/src/structures/MessageEmbed.js +++ b/src/structures/MessageEmbed.js @@ -169,6 +169,20 @@ class MessageEmbed { return this.color ? `#${this.color.toString(16).padStart(6, '0')}` : null; } + /** + * The accumulated length for the embed title, description, fields and footer text + * @type {number} + * @readonly + */ + get length() { + return ( + (this.title ? this.title.length : 0) + + (this.description ? this.description.length : 0) + + (this.fields.length >= 1 ? this.fields.reduce((prev, curr) => + prev + curr.name.length + curr.value.length, 0) : 0) + + (this.footer ? this.footer.text.length : 0)); + } + /** * Adds a field to the embed (max 25). * @param {StringResolvable} name The name of the field diff --git a/typings/index.d.ts b/typings/index.d.ts index d6b95ba60..b167be1f6 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -729,6 +729,7 @@ declare module 'discord.js' { public footer: { text?: string; iconURL?: string; proxyIconURL?: string }; public readonly hexColor: string; public image: { url: string; proxyURL?: string; height?: number; width?: number; }; + public readonly length: number; public provider: { name: string; url: string; }; public thumbnail: { url: string; proxyURL?: string; height?: number; width?: number; }; public timestamp: number;