RawReactionActionEvent

RawReactionActionEvent

本文介绍了如何从消息 ID 中获取消息内容/嵌入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我想知道如何从 message id 获取消息内容(特别是嵌入)?就像您可以使用 member id

I want to know how to get a message content (specifically the embeds) from the message id? Just like you can get the member using a 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)

在我传递 channelmsgID 的命令中,因此示例命令执行类似于 !getmsg #general 112233445566778899 -频道必须与您正在执行命令的服务器位于同一台服务器中!

In the command I'm passing in channel and msgID, so a sample command execution would like !getmsg #general 112233445566778899 - the channel must be in the same server that you're executing the command in!

然后我使用 fetch_message() 协程获取消息对象,它允许我在所述消息中获取 embeds 列表.然后我通过选择位置索引 0 来选择第一个也是唯一一个嵌入.

Then I'm getting the message object using the fetch_message() coroutine, which allows me to get a list of embeds in said message. I then choose the first, and only, embed by choosing position index 0.

之后,机器人会发送嵌入的描述(或您想要的任何属性).

After that, the bot then sends the description (or whatever attribute you'd like) of the embed.

参考资料:

这篇关于如何从消息 ID 中获取消息内容/嵌入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 00:23