How to get most recent messages from channel

I'm trying to have my bot get the most recent message of the channel, but it's returning undefined. How would i do that?
6 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
BestSpark687090
BestSpark687090OP3y ago
npm list discord.js
gamebot@ C:\Users... └── [email protected]
node -v
v16.18.0
CanineData
CanineData3y ago
To get the most recent messages you can do <Channel>.messages.fetch({limit: <However many messages you want to fetch>})
BestSpark687090
BestSpark687090OP3y ago
client.once(Events.ClientReady, c => {
channel = client.channels.cache.get('1053340012021821593');
message = channel.messages.fetch({limit: 1})
.then(message)
.catch(console.error);
});
client.once(Events.ClientReady, c => {
channel = client.channels.cache.get('1053340012021821593');
message = channel.messages.fetch({limit: 1})
.then(message)
.catch(console.error);
});
I did that, but when i console.log it, it is undefined.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?