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 toolkit12mo 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
LolGamer12mo ago
My npm list is: betabotgamer@ /home/pi/betabotgamer ├── @discordjs/opus@0.9.0 ├── @discordjs/voice@0.16.0 ├── booru@2.6.3 ├── chalk@4.1.2 ├── discord.js@14.11.0 ├── ffmpeg-static@5.1.0 ├── ffmpeg@0.0.4 ├── fluent-ffmpeg@2.1.2 ├── prism-media@1.3.5 ├── prism@4.1.2 ├── sodium-native@4.0.3 └── ytdl-core@4.11.4
duck
duck12mo 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
LolGamer12mo ago
Oh, so, if I don't fetch them I won't see all of them in the cache right?
duck
duck12mo ago
yes
LolGamer
LolGamer12mo 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
duck12mo ago
fetch is asynchronous with that code, the log will execute before fetching finishes
LolGamer
LolGamer12mo ago
client.guilds.cache.forEach(async guild => {await guild.members.fetch()}) ? Still 4
duck
duck12mo 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
LolGamer12mo 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
LolGamer12mo ago