How do I get the most recent message in discord.js?

Every time a message is sent in a specific channel, I want to print it to the console (with console.log). I am also going to color it with npm install colors. I go everywhere, even on Stack Overflow, but I cannot seem to find any information. I am coding a Scholastic Bowl-helping bot. Below is the code I have tried (I found this on Stack Overflow.)

message.fetch({ limit: 1 }).then(messages => {
  let lastMessage = message.first();
    if ( = 'channel-id'){

(Note that when I say 'channel-id' I mean the actual ID of the channel.)

The error I am getting is that message.first is not a thing.

How do I fix this error, and how can I get the most recent message in discord.js?

Read more here:

Content Attribution

This content was originally published by MJ535 at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: