Jimothy Cardotha
Jimothy Cardotha

Reputation: 103

Discord JS Client only has itself in guild members cache

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

Answers (3)

Jimothy Cardotha
Jimothy Cardotha

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,

enter image description here

next, add this the place where you instantiated the client

client = new Client({ fetchAllMembers: true }}

Upvotes: 2

Dinty
Dinty

Reputation: 642

It's possible that you haven't enabled the Server Members Intent, which you can enable here:

Server Members Intent

Enabling this should allow you to fetch all members in a guild.

Upvotes: 3

Ethan Snow
Ethan Snow

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

Related Questions