mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 03:18:17 +00:00
refactor!: move dirs outside of src/ (#2032)
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
import type { GuildMemberWithUser } from "../../types/members/guildMember.ts";
|
||||
import type { SearchGuildMembers } from "../../types/members/searchGuildMembers.ts";
|
||||
import { Collection } from "../../util/collection.ts";
|
||||
import { Bot } from "../../bot.ts";
|
||||
|
||||
/**
|
||||
* Query string to match username(s) and nickname(s) against
|
||||
*/
|
||||
export async function searchMembers(
|
||||
bot: Bot,
|
||||
guildId: bigint,
|
||||
query: string,
|
||||
options?: Omit<SearchGuildMembers, "query">,
|
||||
) {
|
||||
if (options?.limit) {
|
||||
if (options.limit < 1) throw new Error(bot.constants.Errors.MEMBER_SEARCH_LIMIT_TOO_LOW);
|
||||
if (options.limit > 1000) {
|
||||
throw new Error(bot.constants.Errors.MEMBER_SEARCH_LIMIT_TOO_HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
const result = await bot.rest.runMethod<GuildMemberWithUser[]>(
|
||||
bot.rest,
|
||||
"get",
|
||||
bot.constants.endpoints.GUILD_MEMBERS_SEARCH(guildId),
|
||||
{
|
||||
...options,
|
||||
query,
|
||||
},
|
||||
);
|
||||
|
||||
return new Collection(
|
||||
result.map((member) => {
|
||||
const m = bot.transformers.member(bot, member, guildId, bot.transformers.snowflake(member.user.id));
|
||||
return [m.id, m];
|
||||
}),
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user