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

Viewed 541

Here's my goal: Check if the message containing the command is a reply to other message If it is then check the content of the message user replied to. For example: Message 1: Hello! How are you? Message 2 (a reply to message 1): !command

Now I want my bot to check if message 2 is a reply and if it is, check and console.log contents of message 1

I'm using discord.js v13.

1 Answers

You can use <Message>.reference to check for a reply.

For example, to check if msg2 is a reply to msg1 and log the contents of msg1:

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

If you don't have msg1 and you need to find it, you can use <Message>.fetchReference to fetch the reply.

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