1

I am trying to make it so when someone sends an image in an embed message the bot will save the image. I already figured out how to do it when someone sends an image as an attachment, but I can't figure out how to do it when the attachments are inside of embeds. Can someone help me? I'm very new to discord.py or coding in general, so I'm trying to mess around with it.

DetKewlDog
  • 11
  • 1

1 Answers1

0

A Message object has an embeds attribute which is a List of Embed objects. Embed objects have an image attribute which contains the URL to the image.

With that knowledge we can do the following (simplified logic-first code):

import discord
import urllib

# purposely left out command boilerplate...

embeds = message.embeds
for embed in embeds:
    image_url = embed.image.url
    # check whether there is an image url
    if image_url != discord.Embed.Empty:
        # as seen on https://stackoverflow.com/a/8286449/13042738
        # save image to `filename.jpg`
        urllib.request.urlretrieve(image_url, "filename.jpg")
Jason Rebelo Neves
  • 1,131
  • 10
  • 20