from PIL import Image, ImageDraw, [email protected]()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"))我將如何發送創建的圖像Pillow.py而不必先保存圖像。我試圖搜索 Stack Overflow 以找到對此的有效響應,但是我沒有找到任何有效的方法。任何幫助表示贊賞!以前我嘗試使用 IO 來解決這個問題,但它最終只會發送空文件。
1 回答

慕村225694
TA貢獻1880條經驗 獲得超4個贊
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'))
使用 seek 就可以了。
添加回答
舉報
0/150
提交
取消