Z
Z
Zero None2021-08-11 13:17:52
Python
Zero None, 2021-08-11 13:17:52

How to edit an image in Embed?

I have code

embed = Embed(title='Image')
embed.set_image(url='https://logos-world.net/wp-content/uploads/2020/12/Discord-Logo.png') # Прикрепляет изображение по ссылке
m = await ctx.send(embed=embed)
embed = Embed(title='Image')
embed.set_image(url='attachment://C:/Users/PC/Desktop/card.png') # Пытаюсь прикрепить изображение с диска
await m.edit(embed=embed) # Обновляю

But the problem is that when you update, only the text of the embed remains, and all the images disappear.
I climbed a bunch of forums, but everyone has a problem only with sending an image, but there is no problem similar to mine.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
retUrn3d, 2021-08-13
@ZERRITO

The bottom line is that discord does not allow you to attach files directly from your computer.
However, this limitation can be circumvented by first sending the file to some channel, and then poking a link to the file from it.
Made for you a clumsy, but very visual demonstration.

@bot.command()
async def test(ctx):
    emb = discord.Embed(title="Image", colour=discord.Color.purple()) # Инициализируем Embed, который будет изменен.
    emb.set_image(url='https://i.imgur.com/mtKT52F.jpeg') # Прикрепляем к Embed'у изображение из интернетов.
    res = await ctx.send(embed=emb)
    new_emb = res.embeds[0] # Получаем наш Embed из первого сообщения.
    file = discord.File('ImageInPc.png', filename="ImageToDiscord.png")
    img_msg = await ctx.send(file=file) # Отправляем картинку в канал, чтобы после этого получить на нее ссылку.
    await asyncio.sleep(5) # Спим для наглядности.
    new_emb.set_image(url=img_msg.attachments[0].url) # img_msg.attachments[0].url - Искомая ссылка на файл.
    await res.edit(embed=new_emb) # Отправляем наш измененный Embed.

X
x4zx, 2021-08-11
@x4zx

If you want to send an embed then you need to write like this:
embed = discord.Embed(title='Image')
embed.set_image(url=' https://logos-world.net/wp-content/uploads/2020/12. .. ') # Attaches an image via link
m = await ctx.send(embed=embed)
embed = discord.Embed(title='Image')
embed.set_image(url=' attachment://C:/Users/PC/ Desktop/card.png ') # Trying to attach image from disk
await m.edit(embed=embed) # Update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question