Skip to content

Commit

Permalink
feat(EmbedBuilder): add .length (#8682)
Browse files Browse the repository at this point in the history
* feat(Embed): add `.length`

Signed-off-by: RedGuy12 <[email protected]>

* Move to mainlib

Signed-off-by: RedGuy12 <[email protected]>

* types: add typings

---------

Signed-off-by: RedGuy12 <[email protected]>
Co-authored-by: Vlad Frangu <[email protected]>
Co-authored-by: Jiralite <[email protected]>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
4 people authored Jul 7, 2023
1 parent dc73c93 commit 53c17e0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/discord.js/src/structures/EmbedBuilder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const { EmbedBuilder: BuildersEmbed } = require('@discordjs/builders');
const { EmbedBuilder: BuildersEmbed, embedLength } = require('@discordjs/builders');
const { isJSONEncodable } = require('@discordjs/util');
const { toSnakeCase } = require('../util/Transformers');
const { resolveColor } = require('../util/Util');
Expand Down Expand Up @@ -31,6 +31,14 @@ class EmbedBuilder extends BuildersEmbed {
static from(other) {
return new this(isJSONEncodable(other) ? other.toJSON() : other);
}

/**
* The accumulated length for the embed title, description, fields, footer text, and author name.
* @type {number}
*/
get length() {
return embedLength(this.data);
}
}

module.exports = EmbedBuilder;
Expand Down
1 change: 1 addition & 0 deletions packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ export class EmbedBuilder extends BuildersEmbed {
public constructor(data?: EmbedData | APIEmbed);
public override setColor(color: ColorResolvable | null): this;
public static from(other: JSONEncodable<APIEmbed> | APIEmbed): EmbedBuilder;
public get length(): number;
}

export class Embed {
Expand Down

0 comments on commit 53c17e0

Please sign in to comment.