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 toolkit2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
Mattéo
MattéoOP2y ago
Thanks. So there is no way to get the newest messages first ?
Blacku
Blacku2y ago
oldMessages.first()
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Mattéo
MattéoOP2y 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 User2y ago
Message Not Public
Sign In & Join Server To View
grass
grass2y ago
to get the last 100 messages i believe you could do <Collection>.last(100)
d.js docs
d.js docs2y ago
method Collection#last() Obtains the last value(s) in this collection.
Mattéo
MattéoOP2y ago
🙏 Thank you guys
Want results from more Discord servers?
Add your server