diff --git a/packages/builders/__tests__/messages/embed.test.ts b/packages/builders/__tests__/messages/embed.test.ts index eb07db3d9802..3483ac797399 100644 --- a/packages/builders/__tests__/messages/embed.test.ts +++ b/packages/builders/__tests__/messages/embed.test.ts @@ -391,6 +391,22 @@ describe('Embed', () => { ).toThrowError(); }); + test('GIVEN an embed using Embed#setFields THEN returns valid toJSON data', () => { + const embed = new Embed(); + + expect(() => + embed.setFields(...Array.from({ length: 25 }, () => ({ name: 'foo', value: 'bar' }))), + ).not.toThrowError(); + }); + + test('GIVEN an embed using Embed#setFields that sets more than 25 fields THEN throws error', () => { + const embed = new Embed(); + + expect(() => + embed.setFields(...Array.from({ length: 26 }, () => ({ name: 'foo', value: 'bar' }))), + ).toThrowError(); + }); + describe('GIVEN invalid field amount THEN throws error', () => { test('', () => { const embed = new Embed(); diff --git a/packages/builders/src/messages/embed/Embed.ts b/packages/builders/src/messages/embed/Embed.ts index 10e0f3ad6d40..eeb66ab82042 100644 --- a/packages/builders/src/messages/embed/Embed.ts +++ b/packages/builders/src/messages/embed/Embed.ts @@ -170,6 +170,15 @@ export class Embed implements APIEmbed { return this; } + /** + * Sets the embed's fields (max 25). + * @param fields The fields to set + */ + public setFields(...fields: APIEmbedField[]) { + this.spliceFields(0, this.fields.length, ...fields); + return this; + } + /** * Sets the author of this embed *