使用本地文件作为set_image文件discord.py [英] Use a local file as the set_image file discord.py
问题描述
我知道在discord.py中,您可以使嵌入的 set_image
成为图像的URL。但是,我想将计算机上的本地文件用于 set_image
而不是图像的URL。
I am aware that in discord.py, you can make the set_image
of an embed a url of an image. But, I want to use a local file on my computer for the set_image
instead of a url of an 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
如何实现?还有其他功能吗?
How can I achieve this? Is there another function or something?
推荐答案
好,我刚刚得到它。它的代码如下:
Ok I just got it. The code for it is the following:
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
The only thing you should be changing is line 2 where it says "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。
Note: on lines 2 and 3, there is an image.png
. Fret not about it since thats what Discord is calling the uploaded file (Example: I have a file called duck.png
, Discord uploads it to their servers as image.png
). So you don't need to change the image.png
part. However, if you are using a file that the specific extension matters, remember to change the image.png
to the desired extension. An example of a file that requires a specific extension is a GIF so remember to change image.png
to for example, an image.gif
if you are using a GIF.
您可以在discord.py的官方文档中了解更多信息: https://discordpy.readthedocs.io /en/latest/faq.html#how-do-i-use-a-local-image-file-for-embedded-image
You can read more here at discord.py's official documentation: https://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image
这篇关于使用本地文件作为set_image文件discord.py的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!