From be35db2410c24fcca8b28ddfb3c1c580e7e2a22f Mon Sep 17 00:00:00 2001 From: pat <73502164+nyapat@users.noreply.github.com> Date: Sat, 23 Jul 2022 16:39:03 -0500 Subject: [PATCH] refactor(embed): deprecate addField (#8318) 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 --- src/structures/MessageEmbed.js | 11 +++++++++++ typings/index.d.ts | 1 + 2 files changed, 12 insertions(+) diff --git a/src/structures/MessageEmbed.js b/src/structures/MessageEmbed.js index 02367fd85..d87255528 100644 --- a/src/structures/MessageEmbed.js +++ b/src/structures/MessageEmbed.js @@ -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()`. @@ -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 }); } diff --git a/typings/index.d.ts b/typings/index.d.ts index 803b0928b..1aebe7dbe 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -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;