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
- 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!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•16mo ago
Message Not Public
Sign In & Join Server To View
It's going to be a personal small bot. The bot will restart every day I do plan on deleting the cache
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
Thanks, I'll take a look
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
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•16mo ago
Message Not Public
Sign In & Join Server To View
Can I cache 500+ messages?
It doesn't need to be *cached at once
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
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 😢
<Collection>.at(index)
But that collection would only contain 100 messages at most, right? Also messages within 14 days
You can fetch messages from anytime. Just not bulk delete
I don't plan on deleting any messages
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.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 oneUnknown User•16mo ago
Message Not Public
Sign In & Join Server To View
I see
Unknown User•16mo ago
Message Not Public
Sign In & Join Server To View
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.
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
Yes i thing you can do that