Programming-Study-Group / Dalle-Bot

A discord bot generating images using dalle-mini
3 stars 0 forks source link

Display the Generated Images on Discord #2

Open KarahanS opened 2 years ago

KarahanS commented 2 years ago

Currently, our bot seems to be able to display the generated image on Discord as can be seen:

s

However, on the background I save each image in memory first and then send to the Discord.

images = re.search('\[(.*)\]', req.content.decode("utf-8") ).group(0)
encodings = [e.replace("\\n", "") for e in re.findall('"([^"]*)"', images)]
for encoded in encodings:
    with open("image.png", "wb") as fh:
        fh.write(b64decode(encoded))    # get rid of this
        await message.channel.send(file = discord.File("image.png"))

This approach is not favorable given the fact that it requires lots of I/O operations.

Sometimes it's not able to display the image and sends a meaningless file whose size is 0 KB.

KarahanS commented 2 years ago

Solved the second problem with this commit. Most probably, it was due to the fact that I was trying to send the image to Discord in the with block immediately after the writing operation.