fix/feat(MessageEmbed): deep copy fields and fix files when passed into constructor (#1864)

This commit is contained in:
Drahcirius
2017-09-09 17:43:13 -04:00
committed by Crawl
parent c523e224d7
commit 63f6247ce5

View File

@@ -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<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;
});
}
}
/**