python - 如何在 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)
推荐阅读
- android - 如何在特定子视图上调用 onTouchListener
- python - 如何使用 cartopy 中的 lat lon 对在 Albera 等面积投影中绘图?
- python - 创建一个文件夹,然后根据需要保存尽可能多的 .txt 文档
- ruby-on-rails - 无法使用 RubyMine 运行 RSPec。RSpec 在 ubuntu 终端上运行良好
- magento2 - Magento 2.4.2 类别仅限于前端 10,000 个产品
- python - 使用 ODEINT 求解两个微分方程
- swift - Swift - 格式“昨天”+时间和周+本地化时间
- json - PowerShell - 在包含 JSON 引号的变量中传递变量
- sql - 在like中使用oracle sql
- sql - 访问 SQL 查询组前 1