首页 > 解决方案 > 如何在 discord.py 中嵌入我的机器人的响应

问题描述

我知道如何在 discord.py 中发送嵌入,但我对这段代码有点困惑 请任何人帮我提供这个命令的代码示例。

@client.command()
    async def wanted(ctx, user: discord.Member = None):
      if user == None:
        user = ctx.author
    
      wanted = Image.open("wanted.jpg")
    
      asset = user.avatar_url_as(size = 128)
      data = BytesIO(await asset.read())
      pfp = Image.open(data) 
    
      pfp = pfp.resize((257, 257))
    
      wanted.paste(pfp, (99, 201))
      wanted.save("profile.jpg")
      await ctx.send(file = discord.File("profile.jpg"))

标签: pythondiscordbotsdiscord.pydiscord.py-rewrite

解决方案


要在嵌入中发送本地图像:

file = discord.File("some_file_path", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png") # Same name as in the file constructor

await ctx.send(file=file, embed=embed)

将调用者的 pfp 添加到嵌入

embed = discord.Embed()
embed.set_image(url=ctx.author.avatar_url)

await ctx.send(embed=embed)

推荐阅读