Files
discordeno/src/helpers/guilds/get_prune_count.ts
T
rigormorrtiss 6f280e7781 change(types): move error & file_content to discordeno/ (#903)
* refactor(types): move errors, file_content module to types/discordeno

* refactor(types): move error & file_content module to discordeno/

* Update and fix import statements
2021-05-05 17:19:28 +01:00

28 lines
1006 B
TypeScript

import { rest } from "../../rest/rest.ts";
import type { GetGuildPruneCountQuery } from "../../types/guilds/get_guild_prune_count.ts";
import { Errors } from "../../types/discordeno/errors.ts";
import { endpoints } from "../../util/constants.ts";
import { requireBotGuildPermissions } from "../../util/permissions.ts";
import { camelKeysToSnakeCase } from "../../util/utils.ts";
/** Check how many members would be removed from the server in a prune operation. Requires the KICK_MEMBERS permission */
export async function getPruneCount(
guildId: bigint,
options?: GetGuildPruneCountQuery,
) {
if (options?.days && options.days < 1) throw new Error(Errors.PRUNE_MIN_DAYS);
if (options?.days && options.days > 30) {
throw new Error(Errors.PRUNE_MAX_DAYS);
}
await requireBotGuildPermissions(guildId, ["KICK_MEMBERS"]);
const result = await rest.runMethod(
"get",
endpoints.GUILD_PRUNE(guildId),
camelKeysToSnakeCase(options ?? {}),
);
return result.pruned as number;
}