Reputation: 566
I'm trying to send a buffer as an attachment in Discord.js v13. I'm using the same code that worked in v11, with the necessary syntax changes to v13.
The image at the specified path does exist and if I save the buffer to my disk as an image, it works just fine.
If I send it as an attachment in Discord it results in an empty attachment like this:
This is my code:
const promise = fs.promises.readFile(path.join('./assets/Environment/Base.png')); //this image exists
Promise.resolve(promise).then(function(buffer){
message.channel.send({content: `${message.author.username}'s base:\n`, attachment: [buffer]}).catch(allerrors)
});
I asked in several Discord servers, but nobody was able to help me so I thought I'd ask here, does anyone know what could be causing this?
Thanks!
Upvotes: 1
Views: 7529
Reputation: 2847
According to docs, you should send a buffer like this:
message.channel.send({content: `${message.author.username}'s base:\n`, files: [
{ attachment: buffer }
]}).catch(allerrors);
Tested on both discord.js v13 and discord.js v12.
Upvotes: 1