diff --git a/src/structures/MessageEmbed.js b/src/structures/MessageEmbed.js index 5cc2685fc..39fef4492 100644 --- a/src/structures/MessageEmbed.js +++ b/src/structures/MessageEmbed.js @@ -5,6 +5,9 @@ const { RangeError } = require('../errors'); const Util = require('../util/Util'); let deprecationEmittedForSetAuthor = false; +let deprecationEmittedForSetFooter = false; + +// TODO: Remove the deprecated code for `setAuthor()` and `setFooter()`. /** * Represents an embed in a message (image/video preview, rich embed, etc.) @@ -356,11 +359,9 @@ class MessageEmbed { * @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|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. @@ -375,13 +376,9 @@ class MessageEmbed { } if (typeof options === 'string') { - if ( - !deprecationEmittedForSetAuthor && - (typeof deprecatedIconURL !== 'undefined' || typeof deprecatedURL !== 'undefined') - ) { + if (!deprecationEmittedForSetAuthor) { process.emitWarning( - // eslint-disable-next-line max-len - "Passing strings for the URL or the icon's URL for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.", + 'Passing strings for MessageEmbed#setAuthor is deprecated. Pass a sole object instead.', 'DeprecationWarning', ); @@ -416,13 +413,41 @@ class MessageEmbed { return this; } + /** + * The options to provide for setting a footer for a {@link MessageEmbed}. + * @typedef {Object} EmbedFooterData + * @property {string} text The text of the footer. + * @property {string} [iconURL] The icon URL of the footer. + */ + /** * Sets the footer of this embed. - * @param {string} text The text of the footer - * @param {string} [iconURL] The icon URL of the footer + * @param {string|EmbedFooterData|null} options The options to provide for the footer. + * Provide `null` to remove the footer data. + * @param {string} [deprecatedIconURL] The icon URL of this footer. + * This parameter is **deprecated**. Use the `options` parameter instead. * @returns {MessageEmbed} */ - setFooter(text, iconURL) { + setFooter(options, deprecatedIconURL) { + if (options === null) { + this.footer = {}; + return this; + } + + if (typeof options === 'string') { + if (!deprecationEmittedForSetFooter) { + process.emitWarning( + 'Passing strings for MessageEmbed#setFooter is deprecated. Pass a sole object instead.', + 'DeprecationWarning', + ); + + deprecationEmittedForSetFooter = true; + } + + options = { text: options, iconURL: deprecatedIconURL }; + } + + const { text, iconURL } = options; this.footer = { text: Util.verifyString(text, RangeError, 'EMBED_FOOTER_TEXT'), iconURL }; return this; } diff --git a/typings/index.d.ts b/typings/index.d.ts index 186ba0ffd..ee6e9fa2b 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1694,11 +1694,13 @@ 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(options: EmbedAuthorData | null): this; + /** @deprecated Supply a lone object of interface {@link EmbedAuthorData} instead. */ public setAuthor(name: string, iconURL?: string, url?: string): this; public setColor(color: ColorResolvable): this; public setDescription(description: string): this; + public setFooter(options: EmbedFooterData | null): this; + /** @deprecated Supply a lone object of interface {@link EmbedFooterData} instead. */ public setFooter(text: string, iconURL?: string): this; public setImage(url: string): this; public setThumbnail(url: string): this; @@ -4318,6 +4320,11 @@ export interface EmbedFieldData { inline?: boolean; } +export interface EmbedFooterData { + text: string; + iconURL?: string; +} + export type EmojiIdentifierResolvable = string | EmojiResolvable; export type EmojiResolvable = Snowflake | GuildEmoji | ReactionEmoji;