Cache of GuildMembers

Hi, how long does it take for the bot to delete members from cache? For get some full members of some roles i put this code in 'ready' events. When bot starts, guild.members.size returned 100% memberCount but some time latter (about half day), it returns only 20-30% of memberCount. Is there any way to keep the cache always full. I just only want to get full members of some roles at anytime more and than that the presence of the member
const guild = await client.guilds.fetch({ guild: client.config.guildId, force: true, cache: true })
await guild.members.fetch({ cache: true, force: true, withPresences: true })
const guild = await client.guilds.fetch({ guild: client.config.guildId, force: true, cache: true })
await guild.members.fetch({ cache: true, force: true, withPresences: true })
Client Options:
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers
], partials: [
Partials.Message,
Partials.Reaction,
Partials.Channel,
Partials.ThreadMember
],
})
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildPresences,
GatewayIntentBits.GuildMessageReactions,
GatewayIntentBits.GuildVoiceStates,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildEmojisAndStickers
], partials: [
Partials.Message,
Partials.Reaction,
Partials.Channel,
Partials.ThreadMember
],
})
11 Replies
d.js toolkit
d.js toolkit4mo 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!
MrMythical
MrMythical4mo ago
Just fetch when you actually need the members
PNV | Cam
PNV | CamOP4mo ago
i fetched but it return null and 'Unkown Member' error
MrMythical
MrMythical4mo ago
And how are you fetching?
PNV | Cam
PNV | CamOP4mo ago
i wanna get all members of a role but someone told me in #djs-help-v14 that the all the members of this role must be cached so i tried to use this
const guild = await client.guilds.fetch({ guild: '755793441287438469' });
const role = await guild.roles.fetch(role_id, { cache: true, force: true }).catch(() => { })
const guild = await client.guilds.fetch({ guild: '755793441287438469' });
const role = await guild.roles.fetch(role_id, { cache: true, force: true }).catch(() => { })
but role.members doesnt return full members of that role
TÆMBØ
TÆMBØ4mo ago
I don't see where you're fetching members in that code I see you fetching a guild and I see you fetching a role from that guild, but not members
treble/luna
treble/luna4mo ago
also, according to your previous code, you have the Guilds intent, in which case fetching guilds and roles is unnecessary
PNV | Cam
PNV | CamOP4mo ago
if the member of a role wasn't in the cache, will role.members return full member having that role?
treble/luna
treble/luna4mo ago
it relies on member cache So no, if the member isnt cached they won't be included
PNV | Cam
PNV | CamOP4mo ago
so how can i get full member of specific role
treble/luna
treble/luna4mo ago
by fetching guild members first
Want results from more Discord servers?
Add your server