I suggest to use a new property for User called Guilds, this gives a collection of all shared servers with the client, it's still technically possible to do so without it but would be easier this way
the old way ->
```
function userServersCount(id) {
return client.guilds.filter(guild => {
if(guild.members.find("id",id)) return guild;
}).size;
}
the new way ->
user.guilds
```
This seems like a kind of hacky workaround to Discord already not including Mutual Servers with bots. Also, if the user is not cached in said guild it wouldn't show up. You'd also have to cache every guild the bot is in and with sharding this would only return the mutual servers in the same shard. -1 on this suggestion.
If someone's doing sharding, they could do something like:
async function getMutualGuilds(user_id) {
let mutualGuilds = await client.shard.broadcastEval(`let ids = Array.from(this.guilds.keys()), count = 0;
for (let id of ids) {
if (this.guilds.get(id).members.has('${user_id}')) ++count;
};
count;`);
// Now, `mutualGuild` is an array of 'no. of mutual guilds' with the user per shard (of course, only if he's cached)
// So, now, for a total count of mutual guilds, just return the sum of all the array elements.
return mutualGuilds.reduce((sum, val) => sum + val, 0);
}
But having it's support in discord.js would make it easier for everyone to implement something like this with less lines of code. So, +1 for this suggestion.
Most helpful comment
This seems like a kind of hacky workaround to Discord already not including Mutual Servers with bots. Also, if the user is not cached in said guild it wouldn't show up. You'd also have to cache every guild the bot is in and with sharding this would only return the mutual servers in the same shard. -1 on this suggestion.