mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 00:23:30 +01:00
Add sendFile function (#562)
* sendFile * Add default value to filename * eslint * (╯°□°)╯︵ ┻━┻
This commit is contained in:
@@ -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