what is the best method to fetch all guild members from a guild with 100k+ members? #1607
Unanswered
LegendEvent
asked this question in
Q&A
Replies: 1 comment
-
Yes, use this: function fetchAllGuildMembersByBruteforcing(guild, options = {}) {
const defaultQuery = 'abcdefghijklmnopqrstuvwxyz0123456789!"#$%&\'()*+,-./:;<=>?@[]^_`{|}~ ';
let dictionary;
let limit = 100;
let delay = 500;
let depth = 1;
if (options?.limit) limit = options?.limit;
if (options?.delay) delay = options?.delay;
if (options?.depth) depth = options?.depth;
if (typeof limit !== 'number') throw new TypeError('INVALID_TYPE', 'limit', 'Number');
if (limit < 1 || limit > 100) throw new RangeError('INVALID_RANGE_QUERY_MEMBER');
if (typeof delay !== 'number') throw new TypeError('INVALID_TYPE', 'delay', 'Number');
if (typeof depth !== 'number') throw new TypeError('INVALID_TYPE', 'depth', 'Number');
if (depth < 1) throw new RangeError('INVALID_RANGE_QUERY_MEMBER');
if (depth > 2) {
console.warn(`[WARNING] GuildMemberManager#fetchBruteforce: depth greater than 2, can lead to very slow speeds`);
}
if (delay < 500 && !options?.skipWarn) {
console.warn(
`[WARNING] GuildMemberManager#fetchBruteforce: delay is less than 500ms, this may cause rate limits.`,
);
}
let skipValues = [];
// eslint-disable-next-line no-async-promise-executor
return new Promise(async (resolve, reject) => {
for (let i = 1; i <= depth; i++) {
dictionary = _(defaultQuery)
.permutations(i)
.map(v => _.join(v, ''))
.value();
for (const query of dictionary) {
if (guild.members.cache.size >= guild.memberCount) break;
this.client.emit(
'debug',
`[INFO] GuildMemberManager#fetchBruteforce: Querying ${query}, Skip: [${skipValues.join(', ')}]`,
);
if (skipValues.some(v => query.startsWith(v))) continue;
await guild.members._fetchMany({ query, limit })
.then(members => {
if (members.size === 0) skipValues.push(query);
})
.catch(reject);
await guild.client.sleep(delay);
}
}
resolve(guild.members.cache);
});
} Ex const cache = await fetchAllGuildMembersByBruteforcing(guild);
console.log(cache.length); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I found this: #1398 (comment)
Is this still the best method?
Beta Was this translation helpful? Give feedback.
All reactions