Skip to content

Commit

Permalink
feat(embed): add setFields (#7322)
Browse files Browse the repository at this point in the history
  • Loading branch information
ImRodry committed Jan 24, 2022
1 parent d2d3a80 commit bcc5cda
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/builders/__tests__/messages/embed.test.ts
Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions packages/builders/src/messages/embed/Embed.ts
Expand Up @@ -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
*
Expand Down

0 comments on commit bcc5cda

Please sign in to comment.