chore: v2.9.4
- fix fetchMemberList
This commit is contained in:
parent
046a8d46c7
commit
62c71950ac
@ -69,8 +69,14 @@ all examples shown use the "overlap" method
|
|||||||
const guild = client.guilds.cache.get('id');
|
const guild = client.guilds.cache.get('id');
|
||||||
const channel = guild.channels.cache.get('id');
|
const channel = guild.channels.cache.get('id');
|
||||||
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
|
||||||
|
// Overlap (slow)
|
||||||
for (let index = 0; index <= guild.memberCount; index += 100) {
|
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);
|
await delay(500);
|
||||||
}
|
}
|
||||||
console.log(guild.members.cache.size); // will print the number of members in the guild
|
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
|
```js
|
||||||
const guild = client.guilds.cache.get('id');
|
const guild = client.guilds.cache.get('id');
|
||||||
const channel = guild.channels.cache.get('id');
|
const channel = guild.channels.cache.get('id');
|
||||||
// Fetch member #5000
|
// Fetch member range 5000-5099
|
||||||
await guild.members.fetchMemberList(channel, 5000);
|
await guild.members.fetchMemberList(channel, 5000);
|
||||||
```
|
```
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
12
package.json
12
package.json
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "discord.js-selfbot-v13",
|
"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]",
|
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
|
||||||
"main": "./src/index.js",
|
"main": "./src/index.js",
|
||||||
"types": "./typings/index.d.ts",
|
"types": "./typings/index.d.ts",
|
||||||
@ -59,10 +59,10 @@
|
|||||||
"@sapphire/shapeshift": "^3.7.0",
|
"@sapphire/shapeshift": "^3.7.0",
|
||||||
"@types/node-fetch": "^2.6.2",
|
"@types/node-fetch": "^2.6.2",
|
||||||
"@types/ws": "^8.5.3",
|
"@types/ws": "^8.5.3",
|
||||||
"axios": "^1.1.3",
|
"axios": "^1.2.0",
|
||||||
"bignumber.js": "^9.1.0",
|
"bignumber.js": "^9.1.0",
|
||||||
"chalk": "^4.1.2",
|
"chalk": "^4.1.2",
|
||||||
"discord-api-types": "^0.37.17",
|
"discord-api-types": "^0.37.19",
|
||||||
"form-data": "^4.0.0",
|
"form-data": "^4.0.0",
|
||||||
"json-bigint": "^1.0.0",
|
"json-bigint": "^1.0.0",
|
||||||
"node-fetch": "^2.6.1",
|
"node-fetch": "^2.6.1",
|
||||||
@ -84,7 +84,7 @@
|
|||||||
"@types/node": "^16.11.12",
|
"@types/node": "^16.11.12",
|
||||||
"conventional-changelog-cli": "^2.2.2",
|
"conventional-changelog-cli": "^2.2.2",
|
||||||
"dtslint": "^4.2.1",
|
"dtslint": "^4.2.1",
|
||||||
"eslint": "^8.27.0",
|
"eslint": "^8.28.0",
|
||||||
"eslint-config-prettier": "^8.3.0",
|
"eslint-config-prettier": "^8.3.0",
|
||||||
"eslint-plugin-import": "^2.25.3",
|
"eslint-plugin-import": "^2.25.3",
|
||||||
"eslint-plugin-prettier": "^4.2.1",
|
"eslint-plugin-prettier": "^4.2.1",
|
||||||
@ -92,9 +92,9 @@
|
|||||||
"is-ci": "^3.0.1",
|
"is-ci": "^3.0.1",
|
||||||
"jest": "^28.1.3",
|
"jest": "^28.1.3",
|
||||||
"lint-staged": "^12.1.4",
|
"lint-staged": "^12.1.4",
|
||||||
"prettier": "^2.5.1",
|
"prettier": "^2.8.0",
|
||||||
"tsd": "^0.24.1",
|
"tsd": "^0.24.1",
|
||||||
"tslint": "^6.1.3",
|
"tslint": "^6.1.3",
|
||||||
"typescript": "^4.8.4"
|
"typescript": "^4.9.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,6 +213,7 @@ const Messages = {
|
|||||||
NORMAL_LOGIN: 'Username and password are required for normal login',
|
NORMAL_LOGIN: 'Username and password are required for normal login',
|
||||||
LOGIN_FAILED_UNKNOWN: 'Login failed',
|
LOGIN_FAILED_UNKNOWN: 'Login failed',
|
||||||
LOGIN_FAILED_2FA: 'Login failed, 2FA code is required',
|
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);
|
for (const [name, message] of Object.entries(Messages)) register(name, message);
|
||||||
|
@ -487,45 +487,58 @@ class GuildMemberManager extends CachedManager {
|
|||||||
* Fetches multiple members from the guild.
|
* Fetches multiple members from the guild.
|
||||||
* @param {GuildTextChannelResolvable} channel The channel to get members from (Members has VIEW_CHANNEL permission)
|
* @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 {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
|
* @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
|
* @see https://github.com/aiko-chan-ai/discord.js-selfbot-v13/blob/main/Document/FetchGuildMember.md
|
||||||
* @returns {Collection<Snowflake, GuildMember>} Members in the guild
|
* @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);
|
const channel_ = this.guild.channels.resolve(channel);
|
||||||
if (!channel_?.isText()) throw new TypeError('INVALID_TYPE', 'channel', 'GuildTextChannelResolvable');
|
if (!channel_?.isText()) throw new TypeError('INVALID_TYPE', 'channel', 'GuildTextChannelResolvable');
|
||||||
if (typeof offset !== 'number') throw new TypeError('INVALID_TYPE', 'offset', 'Number');
|
if (typeof offset !== 'number') throw new TypeError('INVALID_TYPE', 'offset', 'Number');
|
||||||
if (typeof time !== 'number') throw new TypeError('INVALID_TYPE', 'time', '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) => {
|
return new Promise((resolve, reject) => {
|
||||||
const default_ = [[0, 99]];
|
const default_ = [[0, 99]];
|
||||||
const fetchedMembers = new Collection();
|
const fetchedMembers = new Collection();
|
||||||
if (offset === 0) {
|
if (offset > 99) {
|
||||||
default_.push([100, 199]);
|
// eslint-disable-next-line no-unused-expressions
|
||||||
} else {
|
double
|
||||||
default_.push([offset, offset + 99], [offset + 100, offset + 199]);
|
? default_.push([offset, offset + 99], [offset + 100, offset + 199])
|
||||||
|
: default_.push([offset, offset + 99]);
|
||||||
}
|
}
|
||||||
this.guild.shard.send({
|
let retry = 0;
|
||||||
op: Opcodes.LAZY_REQUEST,
|
|
||||||
d: {
|
|
||||||
guild_id: this.guild.id,
|
|
||||||
typing: true,
|
|
||||||
threads: true,
|
|
||||||
activities: true,
|
|
||||||
channels: {
|
|
||||||
[channel_.id]: default_,
|
|
||||||
},
|
|
||||||
thread_member_lists: [],
|
|
||||||
members: [],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const handler = (members, guild, type, raw) => {
|
const handler = (members, guild, type, raw) => {
|
||||||
timeout.refresh();
|
timeout.refresh();
|
||||||
if (guild.id !== this.guild.id) return;
|
if (guild.id !== this.guild.id) return;
|
||||||
if (type == 'INVALIDATE' && offset > 100) {
|
if (type == 'INVALIDATE' && offset > 100) {
|
||||||
clearTimeout(timeout);
|
if (retry < retryMax) {
|
||||||
this.client.removeListener(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
console.log('Retrying...');
|
||||||
this.client.decrementMaxListeners();
|
this.guild.shard.send({
|
||||||
reject(new Error('INVALIDATE_MEMBER', raw.ops[0].range));
|
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 {
|
} else {
|
||||||
for (const member of members.values()) {
|
for (const member of members.values()) {
|
||||||
fetchedMembers.set(member.id, member);
|
fetchedMembers.set(member.id, member);
|
||||||
@ -543,6 +556,20 @@ class GuildMemberManager extends CachedManager {
|
|||||||
}, time).unref();
|
}, time).unref();
|
||||||
this.client.incrementMaxListeners();
|
this.client.incrementMaxListeners();
|
||||||
this.client.on(Events.GUILD_MEMBER_LIST_UPDATE, handler);
|
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: [],
|
||||||
|
},
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -192,7 +192,7 @@ class Options extends null {
|
|||||||
referrer_current: 'https://discord.com/channels/@me',
|
referrer_current: 'https://discord.com/channels/@me',
|
||||||
referring_domain_current: 'discord.com',
|
referring_domain_current: 'discord.com',
|
||||||
release_channel: 'stable',
|
release_channel: 'stable',
|
||||||
client_build_number: 159692,
|
client_build_number: 160480,
|
||||||
client_event_source: null,
|
client_event_source: null,
|
||||||
},
|
},
|
||||||
// ? capabilities: 4093,
|
// ? capabilities: 4093,
|
||||||
|
2
typings/index.d.ts
vendored
2
typings/index.d.ts
vendored
@ -3848,6 +3848,8 @@ export class GuildMemberManager extends CachedManager<Snowflake, GuildMember, Gu
|
|||||||
public fetchMemberList(
|
public fetchMemberList(
|
||||||
channel: GuildTextChannelResolvable,
|
channel: GuildTextChannelResolvable,
|
||||||
offset?: number,
|
offset?: number,
|
||||||
|
double?: boolean,
|
||||||
|
retryMax?: number,
|
||||||
time?: number,
|
time?: number,
|
||||||
): Promise<Collection<Snowflake, GuildMember>>;
|
): Promise<Collection<Snowflake, GuildMember>>;
|
||||||
public fetchBruteforce(options?: BruteforceOptions): Promise<Collection<Snowflake, GuildMember>>;
|
public fetchBruteforce(options?: BruteforceOptions): Promise<Collection<Snowflake, GuildMember>>;
|
||||||
|
Loading…
Reference in New Issue
Block a user