Reputation: 3880
I know how to get all members from a guild but I need to do the opposite operation : Getting all the guilds (IDs) where a specified member is registered in.
When fetching user like this client.users.cache.get(memberID);
I don't see anything in the result that can allow me to see all the member's guilds :
User {
id: '706498754712807398',
system: null,
locale: null,
flags: UserFlags { bitfield: 0 },
username: 'johndoe',
bot: false,
discriminator: '1023',
avatar: null,
lastMessageID: null,
lastMessageChannelID: null
}
Any suggestion ?
Upvotes: 0
Views: 1858
Reputation: 3005
You can do this by using the following code:
const userID = '3383083830389'; // the ID of the user
const guilds = client.guilds.cache.filter((guild) => guild.members.cache.has(userID));
and guilds
is a Collection
of guilds where the user is in. This has two limitations :
Upvotes: 2