mirror of
https://github.com/danbulant/discord.js
synced 2026-06-08 01:01:30 +00:00
feat(RichEmbed): add toJSON returning an api-compatible object
This backports:
PR: https://github.com/discordjs/discord.js/pull/3813
Commit: 4ec01ddef5
This commit is contained in:
parent
6eaf63fb7c
commit
97457e1de2
5 changed files with 5 additions and 8 deletions
|
|
@ -152,7 +152,7 @@ class RESTMethods {
|
||||||
content = `${mention}${content ? `, ${content}` : ''}`;
|
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, {
|
return this.rest.makeRequest('patch', Endpoints.Message(message), true, {
|
||||||
content, embed, flags,
|
content, embed, flags,
|
||||||
|
|
|
||||||
|
|
@ -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
|
* @returns {Object} The raw data of this embed
|
||||||
* @private
|
|
||||||
*/
|
*/
|
||||||
_apiTransform() {
|
toJSON() {
|
||||||
return {
|
return {
|
||||||
title: this.title,
|
title: this.title,
|
||||||
type: 'rich',
|
type: 'rich',
|
||||||
|
|
|
||||||
|
|
@ -227,7 +227,7 @@ class Webhook extends EventEmitter {
|
||||||
else options.files = files;
|
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) {
|
if (options.files) {
|
||||||
for (let i = 0; i < options.files.length; i++) {
|
for (let i = 0; i < options.files.length; i++) {
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ class TextBasedChannel {
|
||||||
else options.files = [options.file];
|
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) {
|
if (options.files) {
|
||||||
for (let i = 0; i < options.files.length; i++) {
|
for (let i = 0; i < options.files.length; i++) {
|
||||||
|
|
|
||||||
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
|
|
@ -1120,8 +1120,6 @@ declare module 'discord.js' {
|
||||||
|
|
||||||
export class RichEmbed {
|
export class RichEmbed {
|
||||||
constructor(data?: RichEmbedOptions | MessageEmbed);
|
constructor(data?: RichEmbedOptions | MessageEmbed);
|
||||||
private _apiTransform(): object;
|
|
||||||
|
|
||||||
public author?: { name: string; url?: string; icon_url?: string; };
|
public author?: { name: string; url?: string; icon_url?: string; };
|
||||||
public color?: number;
|
public color?: number;
|
||||||
public description?: string;
|
public description?: string;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue