discord.py发送BytesIO [英] discord.py send BytesIO
本文介绍了discord.py发送BytesIO的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Pillow操作图像,然后想要将其发送到不一致。我的代码:https://paste.pythondiscord.com/comebefupo.py
使用image.show()时,操作后的图像显示良好。
但是,当我要将图像上传到Discorde时,机器人卡住了,没有抛出错误:
got bytes from direct image string
got bytes from member/user pfp or str
opened image
opened draw
drew top text
drew bottom text
prepared buffer
prepared file
# Bot just gets stuck here, no errors
根据多个来源(1、2),我将图像保存到BytesIO流中,然后使用seek(0)
,这样做是正确的。
根据documentation对于不一致的文件,它需要io.BufferedIOBase
,我相信这是我放进去的。
编辑: 请先保存图像,然后再发送该图像。
# Return whole image object
return image
self.convert_bytes(image_bytes, top_text, bottom_text).save('image.png')
await ctx.send(file=discord.File('image.png'))
我不知道为什么这个管用,另一个不管用.
推荐答案
我上周遇到了类似的问题,这是我用来发送图像的代码
with 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))
这篇关于discord.py发送BytesIO的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文