Rapptz / discord.py

An API wrapper for Discord written in Python.
http://discordpy.rtfd.org/en/latest
MIT License
14.92k stars 3.77k forks source link

Allow uploading of file from binary string #433

Closed AlexCMueller closed 7 years ago

AlexCMueller commented 7 years ago

I am making a discord bot for chess. One of the commands that I currently have takes a board in FEN notation, and generates an image of the board, and uploads it to discord. The conversion process is FEN -> svg -> png. By utilizing binary strings for the image data, I am able to do this without any touches to the hard drive or temporary files. However, when it comes time to upload the file, I have to write the data to a temporary file for the sole purpose of uploading, which seems a bit unnecessary.

khazhyk commented 7 years ago

You can do this using BytesIO https://docs.python.org/3.6/library/io.html

send_file(channel, BytesIO("my string"))

AlexCMueller commented 7 years ago

thanks