Bot not seeing all users in v14

I'm trying to update my bot to d.js v14 and I am running into a problem where the bot does not cache all users of the guilds it is in. For instance, first image is from my d.js v12 Bot, and second image is from my d.js v14 Bot. The code I use for the login message is: //Client login and activity client.once(Events.ClientReady, client => { globals.id = client.user.id; globals.avatar = client.user.avatar; console.log("Discord.js v14.11.0"); console.log(Login successful!\n${client.user.username} is now online! Prefix is set to ${prefix}, Version: ${version}); console.log(Bot has started, with ${client.users.cache.size} users, in ${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.); setactivity(client) setInterval(() => { setactivity(client); }, 30000); }); I also enables the Priviledged Gateway Intents on the Developer Portal and I am creating a client with said Intents const client = new Client({ intents: [ GatewayIntentBits.GuildVoiceStates, GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMessageReactions, GatewayIntentBits.GuildMembers, GatewayIntentBits.Guilds, GatewayIntentBits.MessageContent, GatewayIntentBits.DirectMessages, GatewayIntentBits.DirectMessageReactions, ], partials: [ Partials.Channel, Partials.Message ] });
11 Replies
d.js toolkit
d.js toolkit2y ago
• What's your exact discord.js npm list discord.js and node node -v version? • 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.
LolGamer
LolGamerOP2y ago
My npm list is: betabotgamer@ /home/pi/betabotgamer ├── @discordjs/[email protected] ├── @discordjs/[email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] ├── [email protected] └── [email protected]
duck
duck2y ago
members aren't cached by default you'd need to fetch them with <Guild>.members.fetch() you may have been previously utilizing v12's fetchAllMembers client option which just fetched on ready internally this has since been removed you'd need to do it yourself
LolGamer
LolGamerOP2y ago
Oh, so, if I don't fetch them I won't see all of them in the cache right?
duck
duck2y ago
yes
LolGamer
LolGamerOP2y ago
Oh well, thanks duck Hey duck Ehm, it did not work I changed the login into console.log("Discord.js v14.11.0");client.guilds.cache.forEach(guild => {guild.members.fetch()}) console.log(Login successful!\n${client.user.username} is now online! Prefix is set to ${prefix}, Version: ${version}); console.log(Bot has started, with ${client.users.cache.size} users, in ${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.); Yet it keeps saying that it only sees 4 users
duck
duck2y ago
fetch is asynchronous with that code, the log will execute before fetching finishes
LolGamer
LolGamerOP2y ago
client.guilds.cache.forEach(async guild => {await guild.members.fetch()}) ? Still 4
duck
duck2y ago
forEach synchronously iterates each async function will still execute asynchronously you'd probably want to utilize <Collection>.map() and Promise.all() or just use a standard for loop instead
LolGamer
LolGamerOP2y ago
After researching how to make a for loop properly, I came up with this: let guilds = [] client.guilds.cache.forEach((guild) => {guilds.push(guild.id)}) for(let i = 0; i < guilds.length; i++){ let guild = client.guilds.cache.get(guilds[i]) await guild.members.fetch() console.log(i); } console.log(Login successful!\n${client.user.username} is now online! Prefix is set to ${prefix}); console.log(Bot has started, with ${client.users.cache.size} users, in ${client.channels.cache.size} channels of ${client.guilds.cache.size} guilds.); And oh boy it works I can finally rest in peace and wake up to a grateful world Thanks duck, you are the real deal
LolGamer
LolGamerOP2y ago
Want results from more Discord servers?
Add your server