我正在使用Pillow处理图像,然后想要将其发送到Discord。我的代码:https://paste.pythondiscord.com/comebefupo.py
使用image.show()时,可以很好地显示处理后的图像。
然而,当我想上传图像到Discord时,机器人被卡住了,没有抛出错误:
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)。
根据discord.File的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'))我不知道为什么这行得通,而另一件事却不行...
发布于 2020-12-30 01:57:48
上周我遇到了类似的问题,这是我用来发送图像的代码
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)) 发布于 2020-12-30 01:53:29
这不是一个完整的答案,但它可能会有所帮助。
image_file = discord.File(io.BytesIO(image_bytes.encode()),filename=f"{name}.png")
await ctx.send(file=image_file )https://stackoverflow.com/questions/65496133
复制相似问题