Accept File Binaries for File Attachments #395
Replies: 2 comments
-
In fact, it does not have to be saved to a file. You can send an attachment from memory (using the The encoding is a little like this: local base64 = require('openssl').base64
local img_bin = "etc"
local encoded_bin = 'data:.;base64,' .. base64(img_bin)
-- ...
message:reply{
content = 'here is an image attachment sent from memory!',
file = {'img.png', encoded_bin}
} You can also try our Discord server for more help! |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for this information! I saw the table option when I went digging in the source but wasn't sure how to use it. This is AMAZINGLY useful for me so thank you so so much. I'll close this discussion, you answered a question that would have saved me an hour of toying around today if I had known of that server, pop'd in that server and asked haha. EDIT: For refrence of anyone who comes acrossed this I specifically needed to send the decoded version. Base 64 encodng it (with or without the metadata at the start) resulted in a non-functional send that Discord displayed as a file but tossed (404 when attempting to access). In our case it it ended up being most convient for him to send me the base64 encoded image, and for me to decode it and send it through Discordia. |
Beta Was this translation helpful? Give feedback.
-
The Problem: Images fetched to memory as binaries (such as one provided by an API) have to be saved to a file, the file path provided to Discordia, and Discordia re-opens them into memory to send to Discord.
Proposed Solution: Any input that allows the binary to be provided directly to Discordia for shipping to Discord in a :send() call. I wouldn't mind a solution like binaries being a seperate field (ie, {content = 'Test!'; binary = rawImageString}) but I think this cuts out a lot of doubling back on processing required to save a file to disc, re-read it, then delete it after.
Thank you for Discordia, I personally love Lua, and Discordia has let me take a language I enjoy so deeply and make Discord bots. From the bottom of my heart thank you for making it and empowering Lua & Discord lovers.
Beta Was this translation helpful? Give feedback.
All reactions