[英]How to send a discord embed with one image in discord.py?
Rather than just sending an image, I want my discord bot to use Discord embed and have an image attached to it, however, when trying to use set_image and sending a new embed to discord no output is provided.我不只是发送图像,而是希望我的 discord 机器人使用 Discord 嵌入并附加图像,但是,当尝试使用 set_image 并将新嵌入发送到 discord 时,没有提供 output。 I have a file named output.png in my project directory and I just want to see if I can use it within an embed.
我的项目目录中有一个名为 output.png 的文件,我只是想看看是否可以在嵌入中使用它。 Here is some test code I used:
这是我使用的一些测试代码:
@client.command(name='test')
async def test(ctx):
embed = discord.Embed(title='test',colour=discord.Colour.dark_orange())
embed.set_image('output.png')
await ctx.send(embed=embed,file='output.png')
Why does this not produce an embed on discord?为什么这不会在 discord 上生成嵌入?
The embed.set_image
method only accepts an URL of an image, and the file
kwarg of the send
method needs to be a File object, so if you want to send a locally saved image, you need to send it as a file along with the embed, then set the embed image using the attachment://image.png
URL; embed.set_image
方法只接受一个 URL 的图片,而send
方法的file
kwarg 需要是一个File object,所以如果你想发送本地保存的图片,你需要将它作为一个文件连同嵌入,然后使用attachment://image.png
URL; the image.png
can be changed. image.png
可以更改。
file = discord.File("path/to/my/image.png", filename="output.png")
embed = discord.Embed()
embed.set_image(url="attachment://output.png")
await ctx.send(embed=embed, file=file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.