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;
|
||||
}
|
||||
|
||||
|
||||
8
typings/index.d.ts
vendored
8
typings/index.d.ts
vendored
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user