Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(MessageEmbed): Skip validation of field when inside a message #3894

Merged
merged 10 commits into from
Mar 8, 2020
4 changes: 2 additions & 2 deletions src/structures/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class Message extends Base {
* A list of embeds in the message - e.g. YouTube Player
* @type {MessageEmbed[]}
*/
this.embeds = (data.embeds || []).map(e => new Embed(e));
this.embeds = (data.embeds || []).map(e => new Embed(e, true));

/**
* A collection of attachments in the message - e.g. Pictures - mapped by their ID
Expand Down Expand Up @@ -225,7 +225,7 @@ class Message extends Base {
if ('content' in data) this.content = data.content;
if ('pinned' in data) this.pinned = data.pinned;
if ('tts' in data) this.tts = data.tts;
if ('embeds' in data) this.embeds = data.embeds.map(e => new Embed(e));
if ('embeds' in data) this.embeds = data.embeds.map(e => new Embed(e, true));
else this.embeds = this.embeds.slice();

if ('attachments' in data) {
Expand Down
11 changes: 7 additions & 4 deletions src/structures/MessageEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ const Util = require('../util/Util');
* Represents an embed in a message (image/video preview, rich embed, etc.)
*/
class MessageEmbed {
constructor(data = {}) {
this.setup(data);
constructor(data = {}, skipValidation = false) {
this.setup(data, skipValidation);
}

setup(data) {
setup(data, skipValidation) {
MattIPv4 marked this conversation as resolved.
Show resolved Hide resolved
/**
* The type of this embed, either:
* * `rich` - a rich embed
Expand Down Expand Up @@ -65,7 +65,10 @@ class MessageEmbed {
* The fields of this embed
* @type {EmbedField[]}
*/
this.fields = data.fields ? this.constructor.normalizeFields(data.fields) : [];
this.fields = [];
if (data.fields) {
this.fields = skipValidation ? data.fields.map(Util.cloneObject) : this.constructor.normalizeFields(data.fields);
}

/**
* @typedef {Object} MessageEmbedThumbnail
Expand Down