mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 11:28:15 +00:00
fix: members intent fetching (#229)
* fixes fetchMembers #223 * Update guild.ts Co-authored-by: Ayyan <ayyantee@gmail.com>
This commit is contained in:
+17
-1
@@ -417,11 +417,27 @@ export async function pruneMembers(guildID: string, options: PruneOptions) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ⚠️ BEGINNER DEVS!! YOU SHOULD ALMOST NEVER NEED THIS AND YOU CAN GET FROM cache.members.get()
|
||||||
|
*
|
||||||
|
* ADVANCED:
|
||||||
|
* Highly recommended to use this function to fetch members instead of getMember from REST.
|
||||||
|
* REST: 50/s global(across all shards) rate limit with ALL requests this included
|
||||||
|
* GW(this function): 120/m(PER shard) rate limit. Meaning if you have 8 shards your limit is now 960/m.
|
||||||
|
*/
|
||||||
export function fetchMembers(guild: Guild, options?: FetchMembersOptions) {
|
export function fetchMembers(guild: Guild, options?: FetchMembersOptions) {
|
||||||
if (!(identifyPayload.intents & Intents.GUILD_MEMBERS)) {
|
// You can request 1 member without the intent
|
||||||
|
if (
|
||||||
|
(!options?.limit || options.limit > 1) &&
|
||||||
|
!(identifyPayload.intents & Intents.GUILD_MEMBERS)
|
||||||
|
) {
|
||||||
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
throw new Error(Errors.MISSING_INTENT_GUILD_MEMBERS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (options?.userIDs?.length) {
|
||||||
|
options.limit = options.userIDs.length;
|
||||||
|
}
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
requestAllMembers(guild, resolve, options);
|
requestAllMembers(guild, resolve, options);
|
||||||
}) as Promise<Collection<string, Member>>;
|
}) as Promise<Collection<string, Member>>;
|
||||||
|
|||||||
+2
-1
@@ -327,7 +327,8 @@ export function requestGuildMembers(
|
|||||||
op: GatewayOpcode.RequestGuildMembers,
|
op: GatewayOpcode.RequestGuildMembers,
|
||||||
d: {
|
d: {
|
||||||
guild_id: guildID,
|
guild_id: guildID,
|
||||||
query: options?.query || "",
|
// If a query is provided use it, OR if a limit is NOT provided use ""
|
||||||
|
query: options?.query || (options?.limit ? undefined : ""),
|
||||||
limit: options?.limit || 0,
|
limit: options?.limit || 0,
|
||||||
presences: options?.presences || false,
|
presences: options?.presences || false,
|
||||||
user_ids: options?.userIDs,
|
user_ids: options?.userIDs,
|
||||||
|
|||||||
Reference in New Issue
Block a user