mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 13:03: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;
|
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.
|
* Sets the author of this embed.
|
||||||
* @param {string} name The name of the author
|
* @param {string|EmbedAuthorData|null} options The options to provide for the author.
|
||||||
* @param {string} [iconURL] The icon URL of the author
|
* A string may simply be provided if only the author name is desirable.
|
||||||
* @param {string} [url] The URL of the author
|
* 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}
|
* @returns {MessageEmbed}
|
||||||
*/
|
*/
|
||||||
setAuthor(name, iconURL, url) {
|
setAuthor(options, deprecatedIconURL, deprecatedURL) {
|
||||||
this.author = { name: Util.verifyString(name, RangeError, 'EMBED_AUTHOR_NAME'), iconURL, url };
|
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;
|
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 addField(name: string, value: string, inline?: boolean): this;
|
||||||
public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
|
public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
|
||||||
public setFields(...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 setAuthor(name: string, iconURL?: string, url?: string): this;
|
||||||
public setColor(color: ColorResolvable): this;
|
public setColor(color: ColorResolvable): this;
|
||||||
public setDescription(description: string): this;
|
public setDescription(description: string): this;
|
||||||
@@ -4008,6 +4010,12 @@ export interface EditGuildTemplateOptions {
|
|||||||
description?: string;
|
description?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface EmbedAuthorData {
|
||||||
|
name: string;
|
||||||
|
url?: string;
|
||||||
|
iconURL?: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface EmbedField {
|
export interface EmbedField {
|
||||||
name: string;
|
name: string;
|
||||||
value: string;
|
value: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user