cache question

Hey, my bot is in a server with 200k members and I need to fetch members every 5mins, currently doing members.fetch(), but can I just use guild.members.cache How accurate cache is for that
26 Replies
d.js toolkit
d.js toolkit3w ago
Mark
Mark3w ago
You should only need to fetch members once, and then the cache will update as new members join/leave/update
Steve
Steve3w ago
why do you fetch members every 5min anyway
čamdžić
čamdžićOP3w ago
Cache can hold 200k members? I mean it’s not every 5mins it happens on button interaction but yeah its either that or using cache So im asking if using cache is safe here
Mark
Mark3w ago
The only limit is your memory. d.js does not limit any cache except messages unless you specify otherwise
Shizuka
Shizuka3w ago
as mark said, but you can also use your own cache, and store only the data you need
čamdžić
čamdžićOP3w ago
I need every member of server
Shizuka
Shizuka3w ago
fetch() is expensive and rate-limited
čamdžić
čamdžićOP3w ago
I never got rate limited somehow I only had errors like “Members didn’t arrive in time” 2-3 times a day
Shizuka
Shizuka3w ago
that's the thing, members.cache will not reflect the true number of members unless you've fetched what exactly do you need from each of the members?
čamdžić
čamdžićOP3w ago
Username, nickname, id, displayname Everything basically On button click a modal is opened that asks for query input When you submit modal it will find a member with that query So on every modal submit I fetch members and do members.find
Shizuka
Shizuka3w ago
thats simple, just check the cache first to find that query. If not found, fetch with THAT query
čamdžić
čamdžićOP3w ago
Wdym fetch with that query Do you mean members.fetch({ query)} Or
Shizuka
Shizuka3w ago
No description
čamdžić
čamdžićOP3w ago
Is it possible to use UserSelectMenu in dms? That might be even easier and better
Shizuka
Shizuka3w ago
it does not work
čamdžić
čamdžićOP3w ago
Rip
Shizuka
Shizuka3w ago
that's the best way for it; check the cache first, if not found, fetch
souji
souji3w ago
if you send the required intents and keep the bot online it will update the cache based on the received guild member add and delete events that depends on both how you configured your cache as well as your available memory and the memory footprint you want or have to achieve
čamdžić
čamdžićOP3w ago
I didn’t configured cache Its default
souji
souji3w ago
i've done a server with north of 2 million
čamdžić
čamdžićOP3w ago
And also I gave bot unlimited memory which is like 16gb
souji
souji3w ago
what's much less feasible is fetching 200 people with the paginated endpoint every few minutes
Amgelo
Amgelo3w ago
just do this you don't need every member
souji
souji3w ago
does that actually work on all name variants now? iirc it didn't when globals were introduced (at least for a while)
materwelon
materwelon3w ago
is hydra the username here? Or what exactly is “query”? Because I think you have to pass IDs here? ooo. so hydra is the username :thumbsup:

Did you find this page helpful?