Reputation: 103
So I was trying to access a member from a guild via
client.guilds.cache.find((guild) => guild.id === id).members.cache.find((member) => member.user.username === name)
but when the bot starts up the guild only contains itself until a user sends a message.
Upvotes: 1
Views: 2562
Reputation: 103
Thanks to a combination of both Ethan Snow's and Dinty's answers, I fixed the problem.
First, go to the bot settings and enable server members intent,
next, add this the place where you instantiated the client
client = new Client({ fetchAllMembers: true }}
Upvotes: 2
Reputation: 642
It's possible that you haven't enabled the Server Members Intent
, which you can enable here:
Enabling this should allow you to fetch all members in a guild.
Upvotes: 3
Reputation: 455
You need to enable member fetch When creating the client
client = new Client({fetchAllMembers: true}}
Do note that calling Fetch() on a guild Will Overwrite the internal cached guild.
Upvotes: 1