How to get last messages from a text channel ?

Hello, I would like to get messages from the newest to the oldest in a text channel. My way to get the oldest:
const oldestMessages = await <GuildText>.messages.fetch({ limit: 100 });
const oldestMessages = await <GuildText>.messages.fetch({ limit: 100 });
But how to get the newest ? Thanks guys
10 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Post the full error stack trace, not just the top part! - Show your code! - Explain what exactly your issue is. - Not a discord.js issue? Check out #useful-servers. - Issue solved? Press the button!
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
matteo0003
matteo000311mo ago
Thanks. So there is no way to get the newest messages first ?
Blacku
Blacku11mo ago
oldMessages.first()
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
matteo0003
matteo000311mo ago
There is a solution maybe, I have to get the last part of the messages map like:
const messages = await <GuildText>.messages.fetch();

const lastMessages = messages.slice(100); // To get the last 100 messages
const messages = await <GuildText>.messages.fetch();

const lastMessages = messages.slice(100); // To get the last 100 messages
Unknown User
Unknown User11mo ago
Message Not Public
Sign In & Join Server To View
grass
grass11mo ago
to get the last 100 messages i believe you could do <Collection>.last(100)
d.js docs
d.js docs11mo ago
method Collection#last() Obtains the last value(s) in this collection.
matteo0003
matteo000311mo ago
🙏 Thank you guys