#How to let the bot read the chat history?
5 messages · Page 1 of 1 (latest)
- What's your exact discord.js
npm list discord.jsand nodenode -vversion? - 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!
that is the method for fetching existing, previously sent messages
currently the docs are experiencing issues, so I'll mention a few details:
- it's asynchronous and therefore returns a promise
- it can fetch up to 100 messages at a time, with the (mutually exclusive) options
before,after, andaroundaccepting snowflakes to control which 100 messages are fetched - when fetching multiple messages, it will resolve in a
Collection<string, Message>keyed by message id - it can also be used to fetch a single Message by id in which case it will just resolve in the Message object
Thanks @woven cobalt!
I'm wondering when the last update of this function was. If I saw some related resources but it's from 2021, are they still applicable now?
I'm also thinking to fetch the history using timestamp (e.g. within 5mins), should I take a look into the snowflakes thing?
I'm very new to the discord api and JS stuffs🙈
If I saw some related resources but it's from 2021, are they still applicable now?
potentially not
it's probable that you'd be looking at the v13 usage, and I don't remember off the top of my head whether it was a single object param back then
I'm also thinking to fetch the history using timestamp (e.g. within 5mins), should I take a look into the snowflakes thing?
because you can only fetch up to 100 messages at a time, it's entirely possible that you won't be able to fetch all messages within a given time frame without making copious amounts of requests, which would be considered api spam
probably just best to work with a smaller amount of the most recent messages and simply<Collection>.filter()to ensure that you're only working with ones within the given time frame