How do you get a linked message in discord.js?
I want to add a mod command to my discord.js bot that adds a message to the starboard. The way I want it to work is if someone types in !mod starboard _____ (message link) the linked message will be added to the starboard. I know how to add that message to the starboard once I have it but I don't know how to get the message. The code below is what I have so far, but it says it can't read "first" of "undefined." What is the proper syntax?
const targetmessage = message.mentions.message.first();
This is the way message links work:
https://discord.com/channels/guildId/channelId/messageId
Use simple regex to get each id
// "link" is the message link which you have to get on your own
const ids = link.match(/\d+/g)
const message = await client.channels.cache.get(ids[1])?.messages.fetch(ids[2]).catch(err => null) ?? null
This returns the message if found, or null if not. Replace client
with the guild you want if it needs to be guild specific.