Kai*_*Kai 2 python-3.x discord.py-rewrite
我目前正在编写一个不和谐的机器人,discord.py Rewrite我想将图像附加到嵌入中,但我无法弄清楚。
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)
Run Code Online (Sandbox Code Playgroud)
这个有可能。让我举个例子吧。
# 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)
Run Code Online (Sandbox Code Playgroud)
如果它在目录中,您可以执行 discord.File("images/filename.png", filename="filename.png"),但对于附件:// url,它仍然只是名称,没有目录。