0

I want to use images in my local machine for my bot. But so far I have only heard that it accepts URLs from a website, for example. How do I use my own images? If I understand it correctly, the API uses the URLs to go the site and pick the image. I'm not sure about that. If there's a way to do it, can anyone tell?

Example as to what I mean:

@bot.command()
async def foo(ctx):
    . . .
    embed.set_image(<directory to the file location>)
    . . .

I'm pretty sure this is not possible by how the API makes embeds, but please let me know. Thanks in advance!

2 Answers2

0

Try this:

embed = discord.Embed()
file = discord.File("path/to/my/image.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await ctx.send(file=file, embed=embed)

Similar question/source

RiveN
  • 2,595
  • 11
  • 13
  • 26
0

If you want a picture from a api then do this. I'm use sra in this example

AIOhttp:

async with aiohttp.ClientSession() as session:
    async with session.get("https://some-random-api.ml/animal/dog") as resp:
        response = resp.json()
        image = response["image"] #its a url
await ctx.send(image)

To download an image from a web say its not a url or json type: Read: How to download image using requests

Jerry
  • 153
  • 1
  • 10