Skip to content

Commit

Permalink
refactor(embed): deprecate addField (#8318)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
Co-authored-by: Arjun Sharda <77706434+ArjunSharda@users.noreply.github.com>
Co-authored-by: Almeida <almeidx@pm.me>
  • Loading branch information
4 people committed Jul 23, 2022
1 parent e95caa7 commit be35db2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/structures/MessageEmbed.js
Expand Up @@ -6,6 +6,7 @@ const Util = require('../util/Util');

let deprecationEmittedForSetAuthor = false;
let deprecationEmittedForSetFooter = false;
let deprecationEmittedForAddField = false;

// TODO: Remove the deprecated code for `setAuthor()` and `setFooter()`.

Expand Down Expand Up @@ -314,8 +315,18 @@ class MessageEmbed {
* @param {string} value The value of this field
* @param {boolean} [inline=false] If this field will be displayed inline
* @returns {MessageEmbed}
* @deprecated This method is a wrapper for {@link MessageEmbed#addFields}. Use that instead.
*/
addField(name, value, inline) {
if (!deprecationEmittedForAddField) {
process.emitWarning(
// eslint-disable-next-line max-len
'MessageEmbed#addField is deprecated and will be removed in the next major update. Use MessageEmbed#addFields instead.',
'DeprecationWarning',
);

deprecationEmittedForAddField = true;
}
return this.addFields({ name, value, inline });
}

Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -1765,6 +1765,7 @@ export class MessageEmbed {
public type: string;
public url: string | null;
public readonly video: MessageEmbedVideo | null;
/** @deprecated This method is a wrapper for {@link MessageEmbed#addFields}. Use that instead. */
public addField(name: string, value: string, inline?: boolean): this;
public addFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
public setFields(...fields: EmbedFieldData[] | EmbedFieldData[][]): this;
Expand Down

0 comments on commit be35db2

Please sign in to comment.