在 Discord 上发送枕头图像而不保存图像

Nom*_*n10 4 python python-imaging-library discord.py

from PIL import Image, ImageDraw, ImageFont

@client.command()
async def test(ctx):
   image = Image.open('background.png')
   font = ImageFont.truetype('arial.ttf', size=35)
   draw.text((0, 0), f"Example", fill="white", font=font)

   draw.save("image.png")
   await ctx.send(File=discord.File("image.png"))
Run Code Online (Sandbox Code Playgroud)

我将如何发送创建的图像而Pillow.py无需先保存图像。我试图通过 Stack Overflow 搜索来找到对此的有效响应,但是我没有找到任何有效的方法。任何帮助表示赞赏!之前我尝试使用 IO 来解决这个问题,但最终只是发送空文件。

Nom*_*n10 6

with io.BytesIO() as image_binary:
                    image.save(image_binary, 'PNG')
                    image_binary.seek(0)
                    await ctx.send(file=discord.File(fp=image_binary, filename='image.png'))
Run Code Online (Sandbox Code Playgroud)

通过使用 find 就可以解决问题。