繁体   English   中英

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

[英]How can I send my bot's response in Embed in 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"))

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

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)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM