diff --git a/packages/utils/src/builders/embeds.ts b/packages/utils/src/builders/embeds.ts index f73cc05ed..798013258 100644 --- a/packages/utils/src/builders/embeds.ts +++ b/packages/utils/src/builders/embeds.ts @@ -22,7 +22,7 @@ export class EmbedsBuilder extends Array { #currentEmbedIndex: number = 0 /** - * Adds a new field to the embed fields array. + * Adds a new field to the current embed. * * @param {string} name - Field name * @param {string} value - Field value @@ -43,6 +43,22 @@ export class EmbedsBuilder extends Array { return this } + /** + * Adds multiple new fields to the current embed. + * + * @param {DiscordEmbedField[]} fields - The fields to add + * @returns {EmbedsBuilder} + */ + addFields(fields: DiscordEmbedField[]): this { + if (this.#currentEmbed.fields === undefined) { + this.#currentEmbed.fields = [] + } + + this.#currentEmbed.fields.push(...fields) + + return this + } + /** * Creates a blank embed. * diff --git a/packages/utils/tests/builders.spec.ts b/packages/utils/tests/builders.spec.ts index 8068b96b4..9ab640507 100644 --- a/packages/utils/tests/builders.spec.ts +++ b/packages/utils/tests/builders.spec.ts @@ -22,6 +22,14 @@ describe('builders/embeds.ts', () => { expect(new EmbedsBuilder().setDescription('My Description')).to.eql([{ description: 'My Description' }]) }) + it('should add a field in the embed JSON', () => { + expect(new EmbedsBuilder().addField('firstname', 'firstvalue')).to.eql([ + { + fields: [{ name: 'firstname', value: 'firstvalue', inline: undefined }], + }, + ]) + }) + it('should set the fields in the embed JSON', () => { expect( new EmbedsBuilder().setFields([ @@ -38,6 +46,23 @@ describe('builders/embeds.ts', () => { ]) }) + it('should add the fields in the embed JSON', () => { + expect( + new EmbedsBuilder().addField('firstname', 'firstvalue').addFields([ + { name: 'secondname', value: 'secondvalue' }, + { name: 'thirdname', value: 'thirdvalue', inline: true }, + ]), + ).to.eql([ + { + fields: [ + { name: 'firstname', value: 'firstvalue', inline: undefined }, + { name: 'secondname', value: 'secondvalue' }, + { name: 'thirdname', value: 'thirdvalue', inline: true }, + ], + }, + ]) + }) + it('should set the footer text in the embed JSON', () => { expect(new EmbedsBuilder().setFooter('footer text')).to.eql([{ footer: { text: 'footer text' } }]) })