Skip to content

Commit

Permalink
fix/feat(MessageEmbed): deep copy fields and fix files when passed in…
Browse files Browse the repository at this point in the history
…to constructor (#1864)
  • Loading branch information
Drahcirius authored and iCrawl committed Sep 9, 2017
1 parent c523e22 commit 63f6247
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/structures/MessageEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class MessageEmbed {
* @property {string} value The value of this field
* @property {boolean} inline If this field will be displayed inline
*/
this.fields = data.fields || [];
this.fields = data.fields ? data.fields.map(Util.cloneObject) : [];

/**
* The thumbnail of this embed (if there is one)
Expand Down Expand Up @@ -138,8 +138,13 @@ class MessageEmbed {
* @property {Array<FileOptions|string|MessageAttachment>} files Files to attach
*/
if (data.files) {
for (let file of data.files) if (file instanceof MessageAttachment) file = file.file;
} else { data.files = null; }
this.files = data.files.map(file => {
if (file instanceof MessageAttachment) {
return typeof file.file === 'string' ? file.file : Util.cloneObject(file.file);
}
return file;
});
}
}

/**
Expand Down

0 comments on commit 63f6247

Please sign in to comment.