Pep*_*ppa 4 python python-3.x discord.py
我知道在 discord.py 中,您可以set_image嵌入图像的 url。但是,我想在我的计算机上使用本地文件set_image而不是图像的 url。
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
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?还有其他功能吗?
Pep*_*ppa 13
好的,我刚收到。它的代码如下:
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)
Run Code Online (Sandbox Code Playgroud)
在只有你应该改变的是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-嵌入图像
| 归档时间: |
|
| 查看次数: |
7052 次 |
| 最近记录: |