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

Make sending buffers easier #1459

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/structures/RichEmbed.js
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,8 @@ class RichEmbed {
/**
* Sets the file to upload alongside the embed. This file can be accessed via `attachment://fileName.extension` when
* setting an embed image or author/footer icons. Only one file may be attached.
* @param {FileOptions|string} file Local path or URL to the file to attach, or valid FileOptions for a file to attach
* @param {FileOptions|BufferResolvable} file Local path or URL to the file to attach, or valid FileOptions for a file
* to attach
* @returns {RichEmbed} This embed
*/
attachFile(file) {
Expand Down
5 changes: 3 additions & 2 deletions src/structures/Webhook.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ class Webhook {
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
* @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
* should be replaced with plain-text
* @property {FileOptions|string} [file] A file to send with the message
* @property {FileOptions[]|string[]} [files] Files to send with the message
* @property {FileOptions|BufferResolvable} [file] A file to send with the message
* @property {FileOptions[]|BufferResolvable[]} [files] Files to send with the message
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
* it exceeds the character limit. If an object is provided, these are the options for splitting the message.
Expand Down Expand Up @@ -115,6 +115,7 @@ class Webhook {
for (const i in options.files) {
let file = options.files[i];
if (typeof file === 'string') file = { attachment: file };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to combine the logic instead since you are setting file to the same thing?

if (typeof file === 'string' || Buffer.isBuffer(file)) file = { attachment: file };

else if (Buffer.isBuffer(file)) file = { attachment: file };
if (!file.name) {
if (typeof file.attachment === 'string') {
file.name = path.basename(file.attachment);
Expand Down
7 changes: 4 additions & 3 deletions src/structures/interfaces/TextBasedChannel.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ class TextBasedChannel {
* (see [here](https://discordapp.com/developers/docs/resources/channel#embed-object) for more details)
* @property {boolean} [disableEveryone=this.client.options.disableEveryone] Whether or not @everyone and @here
* should be replaced with plain-text
* @property {FileOptions|string} [file] A file to send with the message **(deprecated)**
* @property {FileOptions[]|string[]} [files] Files to send with the message
* @property {FileOptions|BufferResolvable} [file] A file to send with the message **(deprecated)**
* @property {FileOptions[]|BufferResolvable[]} [files] Files to send with the message
* @property {string|boolean} [code] Language for optional codeblock formatting to apply
* @property {boolean|SplitOptions} [split=false] Whether or not the message should be split into multiple messages if
* it exceeds the character limit. If an object is provided, these are the options for splitting the message
Expand Down Expand Up @@ -91,6 +91,7 @@ class TextBasedChannel {
for (const i in options.files) {
let file = options.files[i];
if (typeof file === 'string') file = { attachment: file };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here.

else if (Buffer.isBuffer(file)) file = { attachment: file };
if (!file.name) {
if (typeof file.attachment === 'string') {
file.name = path.basename(file.attachment);
Expand Down Expand Up @@ -436,7 +437,7 @@ const Deprecated = {

/**
* Send files to this channel.
* @param {FileOptions[]|string[]} files Files to send with the message
* @param {FileOptions[]|BufferResolvable[]} files Files to send with the message
* @param {StringResolvable} [content] Text for the message
* @param {MessageOptions} [options] Options for the message
* @returns {Promise<Message>}
Expand Down