我知道在 discord.py 中,您可以创建 set_image
嵌入图像的 url。但是,我想在我的计算机上使用本地文件作为 set_image
而不是图像的网址。
embed = discord.Embed(title="Title", description="Desc", color=0x00ff00)
embed.set_image(url = "https://example.com/image.png") #this is for set_image using url
我怎样才能做到这一点?还有其他功能吗?
最佳答案
好的,我刚收到。它的代码如下:
embed = discord.Embed(title="Title", description="Desc", color=0x00ff00) #creates embed
file = discord.File("path/to/image/file.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await ctx.send(file=file, embed=embed)
只有你应该改变的是第 2 行,它说
"path/to/image/file.png"
注:在第 2 行和第 3 行,有一个
image.png
.不用担心,因为这就是 Discord 调用上传文件的原因(例如:我有一个名为 duck.png
的文件,Discord 将它以 image.png
的形式上传到他们的服务器)。所以你不需要改变 image.png
部分。但是,如果您使用的是特定扩展名很重要的文件,请记住更改 image.png
到所需的扩展名。需要特定扩展名的文件示例是 GIF,因此请记住更改 image.png
例如,一个 image.gif
如果您使用的是 GIF。您可以在 discord.py 的官方文档中阅读更多内容:https://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image
关于python - 使用本地文件作为 set_image 文件 discord.py,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61578927/