如何从消息id中获取消息content/embed?
How to get the message content/embed from the message id?
我想知道如何从 message id
获取消息内容(特别是嵌入内容)?就像您可以使用 member id
获取成员一样
on_raw_reaction_add()
例子:
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
embed = msg.embeds[0]
# do something you want to
命令示例:
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, msgID: int):
msg = await channel.fetch_message(msgID)
await ctx.send(msg.embeds[0].description)
在我传递的命令中 channel
和 msgID
,因此示例命令执行需要 !getmsg #general 112233445566778899
- 通道必须与您在同一台服务器上在 !
中执行命令
然后我使用 fetch_message()
协程获取消息对象,这允许我在所述消息中获取 embeds
的列表。然后我通过选择位置索引 0
.
选择第一个也是唯一的嵌入
之后,机器人会发送嵌入的描述(或您想要的任何属性)。
参考文献:
discord.TextChannel
TextChannel.fetch_message()
Message.embeds
discord.Embed
- 在这里您可以找到嵌入的不同属性
commands.command()
- 命令装饰器
on_raw_reaction_add()
discord.RawReactionActionEvent
- 从反应事件返回的负载
RawReactionActionEvent.message_id
- 回复的消息的 ID
RawReactionActionEvent.channel_id
- 添加反应的文本频道
我想知道如何从 message id
获取消息内容(特别是嵌入内容)?就像您可以使用 member id
on_raw_reaction_add()
例子:
@bot.event
async def on_raw_reaction_add(payload):
channel = bot.get_channel(payload.channel_id)
msg = await channel.fetch_message(payload.message_id)
embed = msg.embeds[0]
# do something you want to
命令示例:
@bot.command()
async def getmsg(ctx, channel: discord.TextChannel, msgID: int):
msg = await channel.fetch_message(msgID)
await ctx.send(msg.embeds[0].description)
在我传递的命令中 channel
和 msgID
,因此示例命令执行需要 !getmsg #general 112233445566778899
- 通道必须与您在同一台服务器上在 !
然后我使用 fetch_message()
协程获取消息对象,这允许我在所述消息中获取 embeds
的列表。然后我通过选择位置索引 0
.
之后,机器人会发送嵌入的描述(或您想要的任何属性)。
参考文献:
discord.TextChannel
TextChannel.fetch_message()
Message.embeds
discord.Embed
- 在这里您可以找到嵌入的不同属性commands.command()
- 命令装饰器on_raw_reaction_add()
discord.RawReactionActionEvent
- 从反应事件返回的负载RawReactionActionEvent.message_id
- 回复的消息的 IDRawReactionActionEvent.channel_id
- 添加反应的文本频道