Skip to content

Commit

Permalink
feat(RichEmbed): add toJSON returning an api-compatible object
Browse files Browse the repository at this point in the history
This backports:
PR: #3813
Commit: 4ec01dd
  • Loading branch information
SpaceEEC committed Feb 28, 2020
1 parent 6eaf63f commit 97457e1
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/client/rest/RESTMethods.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 2 additions & 3 deletions src/structures/RichEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 1 addition & 1 deletion src/structures/interfaces/TextBasedChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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++) {
Expand Down
2 changes: 0 additions & 2 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 97457e1

Please sign in to comment.