Fetch more than 100 messages in a channel

Hey, I know that I shouldn't fetch more than 100 messages but it's a bot in one server so I wanted to know if there is a way to fetch all messages. Is it possible to slowly cache all messages at bot startup? There will be less than 1'000 messages for now. Currently about 500.
25 Replies
d.js toolkit
d.js toolkit•16mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Enze
EnzeOP•16mo ago
npm list discord.js > 14.12.1 and node -v > 16.20.1 There is no error stack trace, except for the 100 limit in fetch. It would be great if I can slowly cache all messages at bot startup, can even take a few minutes, as long as I don't spam the API.
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Enze
EnzeOP•16mo ago
It's going to be a personal small bot. The bot will restart every day I do plan on deleting the cache
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs•16mo ago
guide Miscellaneous: Cache customization read more
Enze
EnzeOP•16mo ago
Thanks, I'll take a look
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Enze
EnzeOP•16mo ago
Basically I want to pick a random message from all specified channels and post it, sounds silly, I know But would be great if I can find a workaround to the limit
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Enze
EnzeOP•16mo ago
Can I cache 500+ messages? It doesn't need to be *cached at once
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Enze
EnzeOP•16mo ago
Hmm.. so it's probably impossible to do that I forgot about the 14 days delay too One more question: Can I get a random message by index? Let's say I want the 103rd message from the bottom. I guess no, right? Like is there a way to get the 103rd message from a channel? All I need is to get a random message across all messages from specific channels 😢
SpecialSauce
SpecialSauce•16mo ago
<Collection>.at(index)
Enze
EnzeOP•16mo ago
But that collection would only contain 100 messages at most, right? Also messages within 14 days
SpecialSauce
SpecialSauce•16mo ago
You can fetch messages from anytime. Just not bulk delete
Enze
EnzeOP•16mo ago
I don't plan on deleting any messages
SpecialSauce
SpecialSauce•16mo ago
Cacheing the message ids somewhere persistent to retrieve later might be a better approach You can also send the options before, after or around when fetching. It’s basically a timestamp in snowflake form.
Enze
EnzeOP•16mo ago
Just for my understanding. Is it possible for me to get the X message since the beginning? With ignoring the 100 fetch and 14 days limit? Let's say I need the 430th message from the top. Can I somehow get it? I don't have any information on that message. Otherwise I think I should really store the IDs somewhere and pick a random one
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Enze
EnzeOP•16mo ago
I see
Unknown User
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
SpecialSauce
SpecialSauce•16mo ago
100 messages is the max discord will ever send from the api for one api request. There’s not a way to request a message by index from the api. From the cache you can.
Enze
EnzeOP•16mo ago
Can't I fetch like the first 100, then the next 100 and so on? It's fine if I add delays to not spam the api
Youssef
Youssef•16mo ago
Yes i thing you can do that
Want results from more Discord servers?
Add your server