Search code examples
pythondiscordembed

Making a picture show inside of embed in discord with python


I've tried many things but keep getting the same outcome. So I wondered if anyone knows what's causing the problem?

Everytime I type my command it shows the picture first and then the embed like this. Current situation

But what I want it to do is put the image inside of the frame. This is the code I currently have at the moment.

@client.command()
  async def foto(ctx):
  channel = ctx.message.channel
  file_path_type = ["images/*.png"]
  images = glob.glob(random.choice(file_path_type))
  random_image = random.choice(images)
  random_image = random_image[7:len(random_image)]
  print(random_image)
  #await channel.send(file=discord.File(random_image))
  embed = discord.Embed(title="Een star wars icon", description="Zo eh! knap koppie.", 
  color=0x00ff00) 
  file = discord.File("images/"+ random_image, filename= "Star_Wars_Icon.png")
  embed.set_image(url="attachment://" + random_image)
  await channel.send(file=file, embed=embed)

Is there something I have forgotten to add to my code in order for it to put the image inside of the frame? I am pretty new to python so I am already sorry for my coding layout.


Solution

  • embed.set_image() supports only HTTPS links. You can only set image in embed like:

    embed = discord.Embed(title="Een star wars icon", description="Zo eh! knap koppie.", color=0x00ff00).set_image(url="https://some.link")