Reputation: 147
I know you can send from a filename, but I don't have access to the filesystem because I am using Heroku.
client.sendFile(messagedata, writer.toBuffer(), "file.png", "Just a message");
The problem is that
TypeError: client.sendFile is not a function
What equivalent function in discord.js will allow me to send a buffer as a file?
Upvotes: 4
Views: 9490
Reputation: 417
I know it's old, but here's an example with text, to send a file in channel without using filesystem.
const { MessageAttachment } = require('discord.js')
const buffer = Buffer.from('Text in file')
const attachment = new MessageAttachment(buffer, 'file.txt')
channel.send(attachment)
Upvotes: 7
Reputation: 4497
.sendFile()
was deprecated. It's now only .send()
To send a file to a User you do:
message.author.send({
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
}]
})
.then(console.log)
.catch(console.error);
To send the file to a Message Channel you can do:
message.channel.send({
files: [{
attachment: 'entire/path/to/file.jpg',
name: 'file.jpg'
}]
})
.then(console.log)
.catch(console.error);
Upvotes: 2