Get Message By ID: Discord.js

NintendoZaedus picture NintendoZaedus · Mar 23, 2018 · Viewed 36.4k times · Source

I am doing a report system for a discord bot and I want the player to report a specific message by the id so that the moderators can decide if it is offensive or not. I am struggling to find a way to get the message's text from the given id. Is there a possible way of doing this?

Answer

Duncan picture Duncan · Apr 20, 2020

fetchMessage is no longer present in Discord.js starting in version 12, but you can use the fetch method of the MessageManager class from the messages property of the TextChannel class.

msg.channel.messages.fetch("701574160211771462")
  .then(message => console.log(message.content))
  .catch(console.error);