Files
discordeno/helpers/guilds/getBans.ts
ITOH 03996c5f58 refactor: revert "feat: base plugin lib idea (#2308)" (#2336)
* Revert "feat: base plugin lib idea (#2308)"

This reverts commit ffe7cdbc6f.

* fmt
2022-07-02 14:24:43 +01:00

33 lines
1.0 KiB
TypeScript

import type { Bot } from "../../bot.ts";
import { Collection } from "../../util/collection.ts";
import { DiscordBan } from "../../types/discord.ts";
import { User } from "../../transformers/member.ts";
/** Returns a list of ban objects for the users banned from this guild. Requires the BAN_MEMBERS permission. */
export async function getBans(bot: Bot, guildId: bigint, options?: GetBans) {
const results = await bot.rest.runMethod<DiscordBan[]>(
bot.rest,
"GET",
bot.constants.routes.GUILD_BANS(guildId, options),
);
return new Collection<bigint, { reason?: string; user: User }>(
results.map((res) => [
bot.transformers.snowflake(res.user.id),
{
reason: res.reason ?? undefined,
user: bot.transformers.user(bot, res.user),
},
]),
);
}
export interface GetBans {
/** Number of users to return (up to maximum 1000). Default: 1000 */
limit?: number;
/** Consider only users before given user id */
before?: bigint;
/** Consider only users after given user id */
after?: bigint;
}