如何判断一条消息是否为回复,并查看回复的消息内容? (discord.js)

How can I check if a message is a reply and check the replied message content? (discord.js)

这是我的目标: 检查包含命令的消息是否是对其他消息的回复 如果是,则检查用户回复的消息内容。 例如: 留言一:您好!你好吗? 消息 2(对消息 1 的回复):!command

现在我想让我的机器人检查消息 2 是否是回复,如果是,则检查 console.log 消息 1

的内容

我正在使用 discord.js v13.

您可以使用 <Message>.reference 查看回复。

例如,检查msg2是否是对msg1的回复并记录msg1的内容:

if (msg2.type === 'REPLY' && msg2.reference.messageId === msg1.id)
  console.log(msg1.content);

如果您没有 msg1 而您需要查找它,您可以使用 <Message>.fetchReference 来获取回复。

if (msg2.type === 'REPLY') {
  const msg1 = await msg2.fetchReference();
  console.log(msg1.content);
}