From 97457e1de260e367bc6d4c362a77a7e968b1340c Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Fri, 28 Feb 2020 18:29:41 +0100 Subject: [PATCH] feat(RichEmbed): add toJSON returning an api-compatible object This backports: PR: https://github.com/discordjs/discord.js/pull/3813 Commit: 4ec01ddef56272f6bed23dd0eced8ea9851127b7 --- src/client/rest/RESTMethods.js | 2 +- src/structures/RichEmbed.js | 5 ++--- src/structures/Webhook.js | 2 +- src/structures/interfaces/TextBasedChannel.js | 2 +- typings/index.d.ts | 2 -- 5 files changed, 5 insertions(+), 8 deletions(-) diff --git a/src/client/rest/RESTMethods.js b/src/client/rest/RESTMethods.js index 5843e29081d5..59f3c65ae031 100644 --- a/src/client/rest/RESTMethods.js +++ b/src/client/rest/RESTMethods.js @@ -152,7 +152,7 @@ class RESTMethods { content = `${mention}${content ? `, ${content}` : ''}`; } - if (embed instanceof RichEmbed) embed = embed._apiTransform(); + if (embed instanceof RichEmbed) embed = embed.toJSON(); return this.rest.makeRequest('patch', Endpoints.Message(message), true, { content, embed, flags, diff --git a/src/structures/RichEmbed.js b/src/structures/RichEmbed.js index b4083501d94c..5ccb22deeddb 100644 --- a/src/structures/RichEmbed.js +++ b/src/structures/RichEmbed.js @@ -278,11 +278,10 @@ class RichEmbed { } /** - * Transforms the embed object to be processed. + * Transforms the embed to a plain object. * @returns {Object} The raw data of this embed - * @private */ - _apiTransform() { + toJSON() { return { title: this.title, type: 'rich', diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index ca3cb9533ce9..5d82b0c4f1ae 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -227,7 +227,7 @@ class Webhook extends EventEmitter { else options.files = files; } - if (options.embeds) options.embeds = options.embeds.map(e => new RichEmbed(e)._apiTransform()); + if (options.embeds) options.embeds = options.embeds.map(e => new RichEmbed(e).toJSON()); if (options.files) { for (let i = 0; i < options.files.length; i++) { diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index 20230302c6d9..ceaa73b17ce5 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -147,7 +147,7 @@ class TextBasedChannel { else options.files = [options.file]; } - if (options.embed) options.embed = new RichEmbed(options.embed)._apiTransform(); + if (options.embed) options.embed = new RichEmbed(options.embed).toJSON(); if (options.files) { for (let i = 0; i < options.files.length; i++) { diff --git a/typings/index.d.ts b/typings/index.d.ts index 104a99037687..b8353d66fcd2 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -1120,8 +1120,6 @@ declare module 'discord.js' { export class RichEmbed { constructor(data?: RichEmbedOptions | MessageEmbed); - private _apiTransform(): object; - public author?: { name: string; url?: string; icon_url?: string; }; public color?: number; public description?: string;