mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
refactor(MessageEmbed): Utilise an object approach for .setAuthor() (#6966)
Co-authored-by: Almeida <almeidx@pm.me>
This commit is contained in:
@@ -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.
|
||||
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
|
||||
* @param {string} [deprecatedURL] The URL of this author.
|
||||
* <warn>This parameter is **deprecated**. Use the `options` parameter instead.</warn>
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user