17

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?

NintendoZaedus
  • 653
  • 3
  • 8
  • 22

3 Answers3

52

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);
Duncan
  • 954
  • 3
  • 15
  • 23
11

You can retrieve a message by id through

msg.channel.fetchMessage();

The documentation is here. If you want to be able to retrieve a message from any channel by id, you can loop through all channels and catch any errors.

Raymond Zhang
  • 730
  • 6
  • 16
  • Is there any way to get the author of that message? And is there a way to see if the message doesn't exist/exists? – NintendoZaedus Mar 24 '18 at 17:19
  • 3
    Well `fetchMessage` returns a message object, so you can just call the `author` property of it. To check if a message exists, just catch the potential error and if the error occurs that will run. [Documentation is right here.](https://discord.js.org/#/docs/main/stable/class/TextChannel?scrollTo=fetchMessage) – Raymond Zhang Mar 24 '18 at 19:32
0

From the official doc:

channel.messages.fetch('{messageIdGoesHere}')
  .then(message => console.log(message.content))
  .catch(console.error);