Files
discordeno/helpers/guilds/getBans.ts
T
ITOH 1edb3c2110 refactor(bot,plugins/helpers,rest,util)!: improve rest route handling (#2248)
* refactor(bot,helpers,plugins,rest,util)!: improve rest route handling
 - rename endpoints constant to routes
 - simplify routes code by removing bases and function calls
 - url query params can now be passed to the route functions

* style: deno fmt

* fix base stuff

* suggestions
2022-05-25 20:35:25 +02: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;
}