What the bot remembers
In What you receive, readingguild.name or member.roles cost no request. That is because the bot remembers what Discord tells it: when it connects, Discord describes every server it is in, and then sends every change. The bot keeps that in memory and answers from it.
Not everything is kept, and what is kept follows your files, the way intents do:
“Seen” means Discord just sent that member: they wrote, used a command, joined or changed.
This has two consequences for your code, both already met in this tutorial:
- Nothing depends on a member being remembered. What comes with an event or a command is always there: the author of a message, who used a command, the member who joined.
guild.membersis what the bot knows, not everyone; to get one precise member,guild.fetchMember()asks Discord when it has to. - “As it was” depends on it.
memberinmemberLeaveisnullwhen the bot never saw that person;messageinmessageDeleteisnullsince no message is kept.
How memory stays under control
A bot in many servers can still fill the memory of its process. Before that happens, the bot remembers less by itself: it looks at its memory every 30 seconds, and when it stays above 80% of what Node may use, it halves what it keeps (50 members per server instead of 100, then 25…) and tells you withℹ. When memory is fine again, it goes back up, and says so. Servers, channels and roles are never touched.
Only when it already remembers as little as it can and memory is still full does it ask you for something, once:
Map you add to and never empty (a cooldown map that never forgets, a log kept in memory). A lot, and still full: your bot is large; give it more memory.
The limits of Discord
Discord protects itself from bots that ask too much. Every one of these is handled by the framework, and listed here so that you recognise them if they ever show up in a message:
The one limit that is yours to respect is the one Discord enforces on people: a bot that pings, posts or edits too much is removed by the people who added it. The framework can’t help with that.
Recap
- The bot remembers servers, channels, roles fully; members partially; messages not at all. Reading costs nothing, and what comes with an event is always there.
- It frees memory by itself and tells you; it only asks when nothing is left to give up.
- Rate limits, sizes, the 3 seconds, sessions and shards are handled: you never write code for them.
Testing
Check your bot without Discord, every time you change something.
Guide: What your bot remembers
The same, with every message.