diff --git a/src/handlers/guild.ts b/src/handlers/guild.ts index 204eeb174..a4bf1ee17 100644 --- a/src/handlers/guild.ts +++ b/src/handlers/guild.ts @@ -174,6 +174,19 @@ export async function getMember(guildID: string, id: string) { return member; } +/** Returns guild member objects for the specified user by their nickname/username. +* +* ⚠️ **ADVANCED USE ONLY: Your members will be cached in your guild most likely. Only use this when you are absolutely sure the member is not cached.** +*/ +export async function getMembersByQuery(guildID: string, name: string, limit = 1) { + const guild = cache.guilds.get(guildID); + if (!guild) return; + + return new Promise((resolve) => { + requestAllMembers(guild, resolve, { query: name, limit }); + }) +} + /** Create an emoji in the server. Emojis and animated emojis have a maximum file size of 256kb. Attempting to upload an emoji larger than this limit will fail and return 400 Bad Request and an error message, but not a JSON status code. If a URL is provided to the image parameter, Discordeno will automatically convert it to a base64 string internally. */ export async function createEmoji( guildID: string, diff --git a/src/module/basicShard.ts b/src/module/basicShard.ts index fbd9affd4..f69337912 100644 --- a/src/module/basicShard.ts +++ b/src/module/basicShard.ts @@ -269,7 +269,7 @@ export function requestGuildMembers( d: { guild_id: guildID, query: options?.query || "", - limit: options?.query || 0, + limit: options?.limit || 0, presences: options?.presences || false, user_ids: options?.userIDs, nonce, diff --git a/src/module/shardingManager.ts b/src/module/shardingManager.ts index f7d567fdc..edce9fca1 100644 --- a/src/module/shardingManager.ts +++ b/src/module/shardingManager.ts @@ -372,7 +372,11 @@ export async function handleDiscordPayload( if (options.chunk_index + 1 === options.chunk_count) { fetchAllMembersProcessingRequests.delete(options.nonce); - resolve(); + resolve( + options.members.map((member) => + guild.members.get(member.user.id) + ), + ); } } }