mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
backport: fix circular conversion in RichEmbed
This commit is contained in:
@@ -39,7 +39,7 @@ class RichEmbed {
|
||||
|
||||
/**
|
||||
* Timestamp for this Embed
|
||||
* @type {Date}
|
||||
* @type {number}
|
||||
*/
|
||||
this.timestamp = data.timestamp;
|
||||
|
||||
@@ -133,7 +133,7 @@ class RichEmbed {
|
||||
|
||||
/**
|
||||
* Sets the timestamp of this embed.
|
||||
* @param {Date} [timestamp=current date] The timestamp
|
||||
* @param {Date} [timestamp=new Date()] The timestamp
|
||||
* @returns {RichEmbed} This embed
|
||||
*/
|
||||
setTimestamp(timestamp = new Date()) {
|
||||
@@ -215,6 +215,36 @@ class RichEmbed {
|
||||
this.file = file;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms the embed object to be processed.
|
||||
* @returns {Object} The raw data of this embed
|
||||
* @private
|
||||
*/
|
||||
_apiTransform() {
|
||||
return {
|
||||
title: this.title,
|
||||
type: 'rich',
|
||||
description: this.description,
|
||||
url: this.url,
|
||||
timestamp: this.timestamp ? new Date(this.timestamp) : null,
|
||||
color: this.color,
|
||||
fields: this.fields,
|
||||
thumbnail: this.thumbnail,
|
||||
image: this.image ? {
|
||||
url: this.image.url,
|
||||
} : null,
|
||||
author: this.author ? {
|
||||
name: this.author.name,
|
||||
url: this.author.url,
|
||||
icon_url: this.author.iconURL,
|
||||
} : null,
|
||||
footer: this.footer ? {
|
||||
text: this.footer.text,
|
||||
icon_url: this.footer.iconURL,
|
||||
} : null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = RichEmbed;
|
||||
|
||||
@@ -178,6 +178,8 @@ class Webhook {
|
||||
else options.files = files;
|
||||
}
|
||||
|
||||
if (options.embeds) options.embeds = options.embeds.map(e => new RichEmbed(e)._apiTransform());
|
||||
|
||||
if (options.files) {
|
||||
for (let i = 0; i < options.files.length; i++) {
|
||||
let file = options.files[i];
|
||||
|
||||
@@ -135,6 +135,8 @@ class TextBasedChannel {
|
||||
else options.files = [options.file];
|
||||
}
|
||||
|
||||
if (options.embed) options.embed = new RichEmbed(options.embed)._apiTransform();
|
||||
|
||||
if (options.files) {
|
||||
for (let i = 0; i < options.files.length; i++) {
|
||||
let file = options.files[i];
|
||||
|
||||
Reference in New Issue
Block a user