Answer the question
In order to leave comments, you need to log in
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) # Обновляю
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question