fix: embeds optional parameters (#281)

* fix: embeds optional parameters
This commit is contained in:
Free 公園 2024-10-22 10:08:30 -06:00 committed by GitHub
parent ddb320c428
commit 4e6bf3b8bd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -30,8 +30,8 @@ export class Embed {
* @example * @example
* embed.setAuthor({ name: 'John Doe', iconURL: 'https://example.com/avatar.png' }); * embed.setAuthor({ name: 'John Doe', iconURL: 'https://example.com/avatar.png' });
*/ */
setAuthor(author: ObjectToLower<APIEmbedAuthor>): this { setAuthor(author?: ObjectToLower<APIEmbedAuthor>): this {
this.data.author = toSnakeCase(author); this.data.author = author && toSnakeCase(author);
return this; return this;
} }
@ -43,8 +43,8 @@ export class Embed {
* embed.setColor('#FF0000'); * embed.setColor('#FF0000');
* embed.setColor('Blurple'); * embed.setColor('Blurple');
*/ */
setColor(color: ColorResolvable): this { setColor(color?: ColorResolvable): this {
this.data.color = resolveColor(color); this.data.color = color && resolveColor(color);
return this; return this;
} }
@ -55,7 +55,7 @@ export class Embed {
* @example * @example
* embed.setDescription('This is the description of the embed'); * embed.setDescription('This is the description of the embed');
*/ */
setDescription(desc: string): this { setDescription(desc?: string): this {
this.data.description = desc; this.data.description = desc;
return this; return this;
} }
@ -79,8 +79,8 @@ export class Embed {
* @example * @example
* embed.setFields([{ name: 'Field 1', value: 'Value 1' }, { name: 'Field 2', value: 'Value 2' }]); * embed.setFields([{ name: 'Field 1', value: 'Value 1' }, { name: 'Field 2', value: 'Value 2' }]);
*/ */
setFields(fields: APIEmbedField[]): this { setFields(fields?: APIEmbedField[]): this {
this.data.fields = fields; this.data.fields = fields ?? [];
return this; return this;
} }
@ -91,8 +91,8 @@ export class Embed {
* @example * @example
* embed.setFooter({ text: 'This is the footer', iconURL: 'https://example.com/footer.png' }); * embed.setFooter({ text: 'This is the footer', iconURL: 'https://example.com/footer.png' });
*/ */
setFooter(footer: ObjectToLower<Omit<APIEmbedFooter, 'proxy_icon_url'>>): this { setFooter(footer?: ObjectToLower<Omit<APIEmbedFooter, 'proxy_icon_url'>>): this {
this.data.footer = toSnakeCase(footer); this.data.footer = footer && toSnakeCase(footer);
return this; return this;
} }
@ -103,8 +103,8 @@ export class Embed {
* @example * @example
* embed.setImage('https://example.com/image.png'); * embed.setImage('https://example.com/image.png');
*/ */
setImage(url: string): this { setImage(url?: string): this {
this.data.image = { url }; this.data.image = url ? { url } : undefined;
return this; return this;
} }
@ -129,7 +129,7 @@ export class Embed {
* @example * @example
* embed.setTitle('This is the title'); * embed.setTitle('This is the title');
*/ */
setTitle(title: string): this { setTitle(title?: string): this {
this.data.title = title; this.data.title = title;
return this; return this;
} }
@ -141,7 +141,7 @@ export class Embed {
* @example * @example
* embed.setURL('https://seyfert.com'); * embed.setURL('https://seyfert.com');
*/ */
setURL(url: string): this { setURL(url?: string): this {
this.data.url = url; this.data.url = url;
return this; return this;
} }