chore: v2.9.4

- fix fetchMemberList
This commit is contained in:
March 7th 2022-11-23 22:09:24 +07:00
parent 046a8d46c7
commit 62c71950ac
7 changed files with 69 additions and 33 deletions

View File

@ -69,8 +69,14 @@ all examples shown use the "overlap" method
const guild = client.guilds.cache.get('id');
const channel = guild.channels.cache.get('id');
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
// Overlap (slow)
for (let index = 0; index <= guild.memberCount; index += 100) {
await guild.members.fetchMemberList(channel, index);
await guild.members.fetchMemberList(channel, index, index !== 100).catch(() => {});
await delay(500);
}
// Non-overlap (fast)
for (let index = 0; index <= guild.memberCount; index += 200) {
await guild.members.fetchMemberList(channel, index == 0 ? 100 : index, index !== 100).catch(() => {});
await delay(500);
}
console.log(guild.members.cache.size); // will print the number of members in the guild
@ -80,7 +86,7 @@ It's possible that fetchMembers doesn't fetch all not-offline members due to rat
```js
const guild = client.guilds.cache.get('id');
const channel = guild.channels.cache.get('id');
// Fetch member #5000
// Fetch member range 5000-5099
await guild.members.fetchMemberList(channel, 5000);
```

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{
"name": "discord.js-selfbot-v13",
"version": "2.9.3",
"version": "2.9.4",
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js",
"types": "./typings/index.d.ts",
@ -59,10 +59,10 @@
"@sapphire/shapeshift": "^3.7.0",
"@types/node-fetch": "^2.6.2",
"@types/ws": "^8.5.3",
"axios": "^1.1.3",
"axios": "^1.2.0",
"bignumber.js": "^9.1.0",
"chalk": "^4.1.2",
"discord-api-types": "^0.37.17",
"discord-api-types": "^0.37.19",
"form-data": "^4.0.0",
"json-bigint": "^1.0.0",
"node-fetch": "^2.6.1",
@ -84,7 +84,7 @@
"@types/node": "^16.11.12",
"conventional-changelog-cli": "^2.2.2",
"dtslint": "^4.2.1",
"eslint": "^8.27.0",
"eslint": "^8.28.0",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-prettier": "^4.2.1",
@ -92,9 +92,9 @@
"is-ci": "^3.0.1",
"jest": "^28.1.3",
"lint-staged": "^12.1.4",
"prettier": "^2.5.1",
"prettier": "^2.8.0",
"tsd": "^0.24.1",
"tslint": "^6.1.3",
"typescript": "^4.8.4"
"typescript": "^4.9.3"
}
}

View File

@ -213,6 +213,7 @@ const Messages = {
NORMAL_LOGIN: 'Username and password are required for normal login',
LOGIN_FAILED_UNKNOWN: 'Login failed',
LOGIN_FAILED_2FA: 'Login failed, 2FA code is required',
GUILD_IS_LARGE: 'This guild is too large to fetch all members with this method',
};
for (const [name, message] of Object.entries(Messages)) register(name, message);

View File

@ -487,45 +487,58 @@ class GuildMemberManager extends CachedManager {
* Fetches multiple members from the guild.
* @param {GuildTextChannelResolvable} channel The channel to get members from (Members has VIEW_CHANNEL permission)
* @param {number} [offset=0] Start index of the members to get
* @param {boolean} [double=false] Whether to use double range
* @param {number} [retryMax=3] Number of retries
* @param {number} [time=10e3] Timeout for receipt of members
* @see https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/FetchGuildMember.md
* @returns {Collection<Snowflake, GuildMember>} Members in the guild
*/
fetchMemberList(channel, offset = 0, time = 10_000) {
fetchMemberList(channel, offset = 0, double = false, retryMax = 3, time = 10_000) {
const channel_ = this.guild.channels.resolve(channel);
if (!channel_?.isText()) throw new TypeError('INVALID_TYPE', 'channel', 'GuildTextChannelResolvable');
if (typeof offset !== 'number') throw new TypeError('INVALID_TYPE', 'offset', 'Number');
if (typeof time !== 'number') throw new TypeError('INVALID_TYPE', 'time', 'Number');
if (typeof retryMax !== 'number') throw new TypeError('INVALID_TYPE', 'retryMax', 'Number');
if (retryMax < 1) throw new RangeError('INVALID_RANGE_RETRY');
if (typeof double !== 'boolean') throw new TypeError('INVALID_TYPE', 'double', 'Boolean');
// TODO: if (this.guild.large) throw new Error('GUILD_IS_LARGE');
return new Promise((resolve, reject) => {
const default_ = [[0, 99]];
const fetchedMembers = new Collection();
if (offset === 0) {
default_.push([100, 199]);
} else {
default_.push([offset, offset + 99], [offset + 100, offset + 199]);
if (offset > 99) {
// eslint-disable-next-line no-unused-expressions
double
? default_.push([offset, offset + 99], [offset + 100, offset + 199])
: default_.push([offset, offset + 99]);
}
this.guild.shard.send({
op: Opcodes.LAZY_REQUEST,
d: {
guild_id: this.guild.id,
typing: true,
threads: true,
activities: true,
channels: {
[channel_.id]: default_,
},
thread_member_lists: [],
members: [],
},
});
let retry = 0;
const handler = (members, guild, type, raw) => {
timeout.refresh();
if (guild.id !== this.guild.id) return;
if (type == 'INVALIDATE' && offset > 100) {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
this.client.decrementMaxListeners();
reject(new Error('INVALIDATE_MEMBER', raw.ops[0].range));
if (retry < retryMax) {
console.log('Retrying...');
this.guild.shard.send({
op: Opcodes.LAZY_REQUEST,
d: {
guild_id: this.guild.id,
typing: true,
threads: true,
activities: true,
channels: {
[channel_.id]: default_,
},
thread_member_lists: [],
members: [],
},
});
retry++;
} else {
clearTimeout(timeout);
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
this.client.decrementMaxListeners();
reject(new Error('INVALIDATE_MEMBER', raw.ops[0].range));
}
} else {
for (const member of members.values()) {
fetchedMembers.set(member.id, member);
@ -543,6 +556,20 @@ class GuildMemberManager extends CachedManager {
}, time).unref();
this.client.incrementMaxListeners();
this.client.on(Events.GUILD_MEMBER_LIST_UPDATE, handler);
this.guild.shard.send({
op: Opcodes.LAZY_REQUEST,
d: {
guild_id: this.guild.id,
typing: true,
threads: true,
activities: true,
channels: {
[channel_.id]: default_,
},
thread_member_lists: [],
members: [],
},
});
});
}

View File

@ -192,7 +192,7 @@ class Options extends null {
referrer_current: 'https://discord.com/channels/@me',
referring_domain_current: 'discord.com',
release_channel: 'stable',
client_build_number: 159692,
client_build_number: 160480,
client_event_source: null,
},
// ? capabilities: 4093,

2
typings/index.d.ts vendored
View File

@ -3848,6 +3848,8 @@ export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, Gu
public fetchMemberList(
channel: GuildTextChannelResolvable,
offset?: number,
double?: boolean,
retryMax?: number,
time?: number,
): Promise<Collection<Snowflake, GuildMember>>;
public fetchBruteforce(options?: BruteforceOptions): Promise<Collection<Snowflake, GuildMember>>;