mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
Add sendFile function (#562)
* sendFile * Add default value to filename * eslint * (╯°□°)╯︵ ┻━┻
This commit is contained in:
@@ -47,6 +47,10 @@ class DMChannel extends Channel {
|
||||
return;
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return;
|
||||
}
|
||||
|
||||
_cacheMessage() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -124,6 +124,10 @@ class GroupDMChannel extends Channel {
|
||||
return;
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return;
|
||||
}
|
||||
|
||||
_cacheMessage() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -222,6 +222,10 @@ class GuildMember {
|
||||
sendTTSMessage() {
|
||||
return;
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(GuildMember);
|
||||
|
||||
@@ -32,6 +32,10 @@ class TextChannel extends GuildChannel {
|
||||
return;
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return;
|
||||
}
|
||||
|
||||
_cacheMessage() {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -122,6 +122,10 @@ class User {
|
||||
sendTTSMessage() {
|
||||
return;
|
||||
}
|
||||
|
||||
sendFile() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
TextBasedChannel.applyToClass(User);
|
||||
|
||||
@@ -68,7 +68,24 @@ class TextBasedChannel {
|
||||
sendTTSMessage(content, options = {}) {
|
||||
return this.client.rest.methods.sendMessage(this, content, true, options.nonce);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a file to this channel
|
||||
* @param {FileResolvable} attachment The file to send
|
||||
* @param {String} [fileName="file.jpg"] The name and extension of the file
|
||||
* @returns {Promise<Message>}
|
||||
*/
|
||||
sendFile(attachment, fileName = 'file.jpg') {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.client.resolver.resolveFile(attachment)
|
||||
.then(file => {
|
||||
this.client.rest.methods.sendMessage(this, undefined, false, undefined, {
|
||||
file,
|
||||
name: fileName,
|
||||
}).then(resolve).catch(reject);
|
||||
})
|
||||
.catch(reject);
|
||||
});
|
||||
}
|
||||
/**
|
||||
* The parameters to pass in when requesting previous messages from a channel. `around`, `before` and
|
||||
* `after` are mutually exclusive. All the parameters are optional.
|
||||
@@ -173,7 +190,7 @@ function applyProp(structure, prop) {
|
||||
}
|
||||
|
||||
exports.applyToClass = (structure, full = false) => {
|
||||
const props = ['sendMessage', 'sendTTSMessage'];
|
||||
const props = ['sendMessage', 'sendTTSMessage', 'sendFile'];
|
||||
if (full) {
|
||||
props.push('_cacheMessage');
|
||||
props.push('getMessages');
|
||||
|
||||
Reference in New Issue
Block a user