在嵌入中附加文件 (Discord.py) [英] Attach a file in an embed (Discord.py)

查看:19
本文介绍了在嵌入中附加文件 (Discord.py)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用 discord.py Rewrite 编写一个不和谐机器人,我想将图像附加到嵌入中,但我无法弄清楚.

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)

推荐答案

这是可能的.举个例子吧.

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)

如果它在目录中,您可以使用 discord.File("images/filename.png", filename="filename.png"),但对于附件://url,它仍然只是名称, 没有目录.

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.

这篇关于在嵌入中附加文件 (Discord.py)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆