From 73854ee8521fe7149a72aafcba815c6efc5939d6 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Tue, 16 Nov 2021 17:31:08 +0000 Subject: [PATCH] refactor(MessageEmbed): Utilise an object approach for `.setAuthor()` (#6966) Co-authored-by: Almeida --- src/structures/MessageEmbed.js | 33 ++++++++++++++++++++++++++++----- typings/index.d.ts | 8 ++++++++ 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/structures/MessageEmbed.js b/src/structures/MessageEmbed.js index 78284aadc..ce7334a33 100644 --- a/src/structures/MessageEmbed.js +++ b/src/structures/MessageEmbed.js @@ -345,15 +345,38 @@ class MessageEmbed { return this; } + /** + * The options to provide for setting an author for a {@link MessageEmbed}. + * @typedef {Object} EmbedAuthorData + * @property {string} name The name of this author. + * @property {string} [url] The URL of this author. + * @property {string} [iconURL] The icon URL of this author. + */ + + // TODO: Remove the deprecated code in the following method and typings. /** * Sets the author of this embed. - * @param {string} name The name of the author - * @param {string} [iconURL] The icon URL of the author - * @param {string} [url] The URL of the author + * @param {string|EmbedAuthorData|null} options The options to provide for the author. + * A string may simply be provided if only the author name is desirable. + * Provide `null` to remove the author data. + * @param {string} [deprecatedIconURL] The icon URL of this author. + * This parameter is **deprecated**. Use the `options` parameter instead. + * @param {string} [deprecatedURL] The URL of this author. + * This parameter is **deprecated**. Use the `options` parameter instead. * @returns {MessageEmbed} */ - setAuthor(name, iconURL, url) { - this.author = { name: Util.verifyString(name, RangeError, 'EMBED_AUTHOR_NAME'), iconURL, url }; + setAuthor(options, deprecatedIconURL, deprecatedURL) { + if (options === null) { + this.author = {}; + return this; + } + + if (typeof options === 'string') { + options = { name: options, url: deprecatedURL, iconURL: deprecatedIconURL }; + } + + const { name, url, iconURL } = options; + this.author = { name: Util.verifyString(name, RangeError, 'EMBED_AUTHOR_NAME'), url, iconURL }; return this; } diff --git a/typings/index.d.ts b/typings/index.d.ts index 7f3bfe00e..a6b93b00e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1572,6 +1572,8 @@ export class MessageEmbed { public addField(name: string, value: string, inline?: boolean): this; public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this; public setFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this; + public setAuthor(options: string | EmbedAuthorData | null): this; + /** @deprecated Supply a lone object of interface {@link EmbedAuthorData} instead of more parameters. */ public setAuthor(name: string, iconURL?: string, url?: string): this; public setColor(color: ColorResolvable): this; public setDescription(description: string): this; @@ -4008,6 +4010,12 @@ export interface EditGuildTemplateOptions { description?: string; } +export interface EmbedAuthorData { + name: string; + url?: string; + iconURL?: string; +} + export interface EmbedField { name: string; value: string;