diff --git a/src/structures/guild.ts b/src/structures/guild.ts index a1ee116..59393ad 100644 --- a/src/structures/guild.ts +++ b/src/structures/guild.ts @@ -12,9 +12,9 @@ import { MessageNotification, ContentFilter, GuildModifyOptions, - GuildGetPruneCountOptions, GuildGetPruneCountPayload, - GuildPruneCountPayload + GuildPruneCountPayload, + GuildBeginPrunePayload } from '../types/guild.ts' import { Base } from './base.ts' import { CreateGuildRoleOptions, RolesManager } from '../managers/roles.ts' @@ -363,15 +363,15 @@ export class Guild extends Base { return result === undefined ? this : result } - async getPruneCount(options: GuildGetPruneCountOptions): Promise { + async getPruneCount( + days?: number, + includeRoles?: Array + ): Promise { const query: GuildGetPruneCountPayload = { - days: options.days, - include_roles: - options.includeRoles !== undefined - ? options.includeRoles - .map((role) => (role instanceof Role ? role.id : role)) - .join(',') - : undefined + days: days, + include_roles: includeRoles + ?.map((role) => (role instanceof Role ? role.id : role)) + .join(',') } const result: GuildPruneCountPayload = await this.client.rest.get( @@ -385,6 +385,42 @@ export class Guild extends Base { return result.pruned as number } + + async prune( + days?: number, + computePruneCount?: false, + includeRoles?: Array + ): Promise + async prune( + days?: number, + computePruneCount?: true, + includeRoles?: Array + ): Promise + async prune( + days?: number, + computePruneCount?: undefined, + includeRoles?: Array + ): Promise + async prune( + days?: number, + computePruneCount?: boolean, + includeRoles?: Array + ): Promise { + const body: GuildBeginPrunePayload = { + days: days, + compute_prune_count: computePruneCount, + include_roles: includeRoles?.map((role) => + role instanceof Role ? role.id : role + ) + } + + const result: GuildPruneCountPayload = await this.client.rest.post( + GUILD_PRUNE(this.id), + body + ) + + return result.pruned + } } export class GuildIntegration extends Base { diff --git a/src/types/guild.ts b/src/types/guild.ts index 938b6bd..6c4c882 100644 --- a/src/types/guild.ts +++ b/src/types/guild.ts @@ -290,7 +290,8 @@ export interface GuildGetPruneCountPayload { include_roles?: string } -export interface GuildGetPruneCountOptions { +export interface GuildBeginPrunePayload { days?: number - includeRoles?: Array + compute_prune_count?: boolean + include_roles?: string[] }