From 63f6247ce5daf9ae6c065c07ed65aacf8d867dd7 Mon Sep 17 00:00:00 2001 From: Drahcirius Date: Sat, 9 Sep 2017 17:43:13 -0400 Subject: [PATCH] fix/feat(MessageEmbed): deep copy fields and fix files when passed into constructor (#1864) --- src/structures/MessageEmbed.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/structures/MessageEmbed.js b/src/structures/MessageEmbed.js index 2156735c8..4c61441d0 100644 --- a/src/structures/MessageEmbed.js +++ b/src/structures/MessageEmbed.js @@ -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) @@ -138,8 +138,13 @@ class MessageEmbed { * @property {Array} 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; + }); + } } /**