diff --git a/src/client/ClientDataResolver.js b/src/client/ClientDataResolver.js index 1cc447708..687e0afe0 100644 --- a/src/client/ClientDataResolver.js +++ b/src/client/ClientDataResolver.js @@ -202,12 +202,17 @@ class ClientDataResolver { * @typedef {string|Buffer} BufferResolvable */ + /** + * @external Stream + * @see {@link https://nodejs.org/api/stream.html} + */ + /** * Resolves a BufferResolvable to a Buffer. - * @param {BufferResolvable} resource The buffer resolvable to resolve + * @param {BufferResolvable|Stream} resource The buffer or stream resolvable to resolve * @returns {Promise} */ - resolveBuffer(resource) { + resolveFile(resource) { if (resource instanceof Buffer) return Promise.resolve(resource); if (this.client.browser && resource instanceof ArrayBuffer) return Promise.resolve(Util.convertToBuffer(resource)); @@ -232,33 +237,18 @@ class ClientDataResolver { }); } }); + } else if (resource.pipe && typeof resource.pipe === 'function') { + return new Promise((resolve, reject) => { + const buffers = []; + resource.once('error', reject); + resource.on('data', data => buffers.push(data)); + resource.once('end', () => resolve(Buffer.concat(buffers))); + }); } return Promise.reject(new TypeError('REQ_RESOURCE_TYPE')); } - /** - * Converts a Stream to a Buffer. - * @param {Stream} resource The stream to convert - * @returns {Promise} - */ - resolveFile(resource) { - return resource ? this.resolveBuffer(resource) - .catch(() => { - if (resource.pipe && typeof resource.pipe === 'function') { - return new Promise((resolve, reject) => { - const buffers = []; - resource.once('error', reject); - resource.on('data', data => buffers.push(data)); - resource.once('end', () => resolve(Buffer.concat(buffers))); - }); - } else { - throw new TypeError('REQ_RESOURCE_TYPE'); - } - }) : - Promise.reject(new TypeError('REQ_RESOURCE_TYPE')); - } - /** * Data that can be resolved to give an emoji identifier. This can be: * * The unicode representation of an emoji diff --git a/src/structures/Attachment.js b/src/structures/Attachment.js index fd4fa8f80..e4ccbb197 100644 --- a/src/structures/Attachment.js +++ b/src/structures/Attachment.js @@ -1,10 +1,13 @@ /** * Represents an attachment in a message. + * @param {BufferResolvable|Stream} file The file + * @param {string} [name] The name of the file, if any */ class Attachment { constructor(file, name) { this.file = null; - this._attach(file, name); + if (name) this.setAttachment(file, name); + else this._attach(file); } /** @@ -42,7 +45,7 @@ class Attachment { * @returns {Attachment} This attachment */ setFile(attachment) { - this.file.attachment = attachment; + this.file = { attachment }; return this; } @@ -63,10 +66,8 @@ class Attachment { * @private */ _attach(file, name) { - if (file) { - if (typeof file === 'string') this.file = file; - else this.setAttachment(file, name); - } + if (typeof file === 'string') this.file = file; + else this.setAttachment(file, name); } } diff --git a/src/structures/Webhook.js b/src/structures/Webhook.js index 281e98868..a179f545b 100644 --- a/src/structures/Webhook.js +++ b/src/structures/Webhook.js @@ -94,7 +94,7 @@ class Webhook { /** * Send a message with this webhook. * @param {StringResolvable} [content] The content to send - * @param {WebhookMessageOptions} [options={}] The options to provide + * @param {WebhookMessageOptions|MessageEmbed|Attachment|Attachment[]} [options={}] The options to provide * @returns {Promise} * @example * // Send a message diff --git a/src/structures/interfaces/TextBasedChannel.js b/src/structures/interfaces/TextBasedChannel.js index df17aac6c..0bae9cbe9 100644 --- a/src/structures/interfaces/TextBasedChannel.js +++ b/src/structures/interfaces/TextBasedChannel.js @@ -66,7 +66,7 @@ class TextBasedChannel { /** * Send a message to this channel. * @param {StringResolvable} [content] Text for the message - * @param {MessageOptions} [options={}] Options for the message + * @param {MessageOptions|MessageEmbed|Attachment|Attachment[]} [options={}] Options for the message * @returns {Promise} * @example * // Send a message