Add sendFile function (#562)

* sendFile

* Add default value to filename

* eslint

* (╯°□°)╯︵ ┻━┻
This commit is contained in:
Manuel Kraus
2016-08-29 20:01:05 +02:00
committed by Amish Shah
parent df934eccaf
commit d9ae732bfd
10 changed files with 87 additions and 9 deletions

View File

@@ -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');