如何在Embed in discord.py中发送我的机器人的响应

2024-05-14 01:27:56 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道如何在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"))

Tags: 代码pyimagenonedataopenassetawait
1条回答
网友
1楼 · 发布于 2024-05-14 01:27:56

要以嵌入方式发送本地图像,请执行以下操作:

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)

相关问题 更多 >