discord - 我如何编辑和重新设计我的旧嵌入消息
问题描述
在嵌入之前,我在我的不和谐服务器上收到过一些短信。现在我只想编辑我的旧嵌入消息,通过重写一些东西和改变颜色来重新设计它的外观。如何通过消息 ID 编辑特定的嵌入消息?我知道它可以通过使用来编辑自己:
first_embed = Embed(title='embed 1')
new_embed = Embed(title='embed 2')
msg = await ctx.send(embed=first_embed)
await msg.edit(embed=new_embed)
但我真的不知道如何使它工作。它如何在消息 ID 处进行编辑?喜欢检查自己的身份证?
解决方案
您必须创建一个新命令来编辑嵌入并获取嵌入消息的 ID 以及您想要更改为参数的内容。然后您可以获取Embed.copy()
或Embed.to_dict()
获取嵌入的数据,然后更新您作为参数获得的数据。
一个例子是:
@bot.command()
async def editembed(ctx, channel: discord.Chanel, msg_id, title, color):
msg = await channel.fetch_message(msg_id)
embed = msg.embeds[0].to_dict()
embed["title"] = title
embed["color"] = color
await msg.edit(embed = discord.Embed.from_dict())
注意: 机器人没有获取消息属性,因此您必须从通道或上下文中获取它(使用上下文时,您必须在与要编辑的消息相同的通道上发送命令)
推荐阅读
- mysql - 删除连接到 mySQL 的表中的行后,如何更新表以按时间顺序显示 S/n?
- javascript - 如何包装由 mathlive 呈现的嵌套跨度内容
- package-managers - 为什么 pacman 在 aur.archlinux.org/packages 中找不到包?
- mysql - SQLSTATE[23000]:违反完整性约束错误
- airflow - 在使用 PythonVirtualenvOperator 导入的 Utils 模块中使用气流类时,“没有名为气流的模块”
- python - ValueError:太多值无法解包(预期为 5)并应用函数
- python - 导入子包时获取包版本
- python - 列表按数字排序,如果数字相同则按字母排序
- python - Python- 使用 Concurrent.Futures 实现 Matlab 的 Parfor(提供代码示例)
- angular - 使 igx-grid 的第一行不可编辑