Shreyas Patil
Shreyas Patil

Reputation: 21

Discord.py Embed Local File

I tried to add a file from my local device into a discord.py embed. Here's my code below, although its not working please help me

import discord
from discord.ext import commands

client = commands.Bot(command_prefix="!")

@client.command
async def pika(ctx):
  file = discord.File("‪E:\Python\discord.py\Pikachu1.jpg", filename="image.jpg")
  embed = discord.Embed(color=0xFFFFFF)
  embed.set_image(url="E:\Python\discord.py\Pikachu1.jpg")
  await ctx.send(file=file, embed=embed)

Upvotes: 2

Views: 1769

Answers (1)

Taku
Taku

Reputation: 33714

To use a local file for an embed's image, use Discord's attachment:// protocol. (Attribution to Lukasz).

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

https://discordpy.readthedocs.io/en/stable/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image

Upvotes: 2

Related Questions