Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attach a file in an embed (Discord.py)

I am currently writing a discord bot with discord.py Rewrite and I want to attach an image onto an embed but I can't figure it out.

import discord
from discord.ext import commands
from discord import Embeds

crafting_table = Embed(title="Crafting Table", description=discord.File("./images/Crafting_Table_GUI.png"))

@client.command()
async def Info(ctx, *, question):
    if "crafting table" in question:
        await ctx.send(embed=crafting_table)
like image 977
Kai Avatar asked Sep 08 '25 11:09

Kai


1 Answers

This is possible. Let me give an example.

# Rewrite
file = discord.File("filename.png") # an image in the same folder as the main bot file
embed = discord.Embed() # any kwargs you want here
embed.set_image(url="attachment://filename.png")
# filename and extension have to match (ex. "thisname.jpg" has to be "attachment://thisname.jpg")
await ctx.send(embed=embed, file=file)

If it is in a directory, you may do discord.File("images/filename.png", filename="filename.png"), but for the attachment:// url it is still just the name, no directory.

like image 143
Chicken Devs Avatar answered Sep 10 '25 13:09

Chicken Devs