Sending a JSON file as an attachment through a bot

Is it possible to send a JSON file or any file that isn't an image for that matter using discord.js? If so, how?
8 Replies
monbrey
monbrey3y ago
Should be exactly the same?
MrMythical
MrMythical3y ago
you should be able to with new MessageAttachment() since it accepts a buffer
monbrey
monbrey3y ago
Make an attachment using the file/buffer of the data and send it Is that not working for you?
Rodry
RodryOP3y ago
So I'd need to do Buffer.from(JSON.stringify(obj)) right?
MrMythical
MrMythical3y ago
well that should work fine
Rodry
RodryOP3y ago
I was trying with just the raw JSON object and it didn't work, maybe that's why
monbrey
monbrey3y ago
If you're doing from in-memory data yeah I think that's correct since that's how you'd print it to file Might want to pretty it too, idk
Rodry
RodryOP3y ago
yeah that worked, thanks lads!
Want results from more Discord servers?
Add your server