diff --git a/interactions/api/http/guild.py b/interactions/api/http/guild.py index 816f3694d..42d6eaf40 100644 --- a/interactions/api/http/guild.py +++ b/interactions/api/http/guild.py @@ -601,6 +601,32 @@ async def remove_guild_member( Route("DELETE", f"/guilds/{guild_id}/members/{user_id}"), reason=reason ) + async def begin_guild_prune( + self, + guild_id: int, + days: int = 7, + compute_prune_count: bool = True, + include_roles: Optional[List[int]] = None, + ) -> dict: + """ + Begins a prune operation. + + :param guild_id: Guild ID snowflake + :param days: Number of days to count, minimum 1, maximum 30. Defaults to 7. + :param compute_prune_count: Whether the returned "pruned" dict contains the computed prune count or None. + :param include_roles: Role IDs to include, if given. + :return: A dict containing `{"pruned": int}` or `{"pruned": None}` + """ + + payload = { + "days": days, + "compute_prune_count": compute_prune_count, + } + if include_roles: + payload["include_roles"] = ", ".join(str(x) for x in include_roles) + + return await self._req.request(Route("POST", f"/guilds/{guild_id}/prune"), json=payload) + async def get_guild_prune_count( self, guild_id: int, days: int = 7, include_roles: Optional[List[int]] = None ) -> dict: @@ -608,7 +634,7 @@ async def get_guild_prune_count( Retrieves a dict from an API that results in how many members would be pruned given the amount of days. :param guild_id: Guild ID snowflake. - :param days: Number of days to count. Defaults to ``7``. + :param days: Number of days to count, minimum 1, maximum 30. Defaults to 7. :param include_roles: Role IDs to include, if given. :return: A dict denoting `{"pruned": int}` """ diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 918c4f1bc..639443283 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -1905,6 +1905,71 @@ async def get_all_bans(self) -> List[Dict[str, User]]: return res + async def prune( + self, + days: int = 7, + compute_prune_count: bool = True, + include_roles: Optional[Union[List[Role], List[int], List[Snowflake], List[str]]] = MISSING, + ) -> Optional[int]: + """ + Begins a prune operation. + + :param days: Number of days to count, minimum 1, maximum 30. Defaults to 7. + :param compute_prune_count: Whether the returned "pruned" dict contains the computed prune count or None. + :param include_roles: Role IDs to include, if given. + :return: The number of pruned members, if compute_prune_count is not false. Otherwise returns None. + :rtype: Optional[int] + """ + if not self._client: + raise LibraryException(code=13) + + if include_roles is not MISSING: + _roles = [ + int(role.id) if isinstance(role, Role) else int(role) for role in include_roles + ] + else: + _roles = None + + res: dict = await self._client.begin_guild_prune( + guild_id=int(self.id), + days=days, + compute_prune_count=compute_prune_count, + include_roles=_roles, + ) + + return res.get("pruned") + + async def get_prune_count( + self, + days: int = 7, + include_roles: Optional[Union[List[Role], List[int], List[Snowflake], List[str]]] = MISSING, + ) -> int: + """ + Returns the number of members that would be removed in a prune operation. + + :param days: Number of days to count, minimum 1, maximum 30. Defaults to 7. + :param include_roles: Role IDs to include, if given. + :return: The number of members that would be pruned. + :rtype: int + """ + if not self._client: + raise LibraryException(code=13) + + if include_roles is not MISSING: + _roles = [ + int(role.id) if isinstance(role, Role) else int(role) for role in include_roles + ] + else: + _roles = None + + res: dict = await self._client.get_guild_prune_count( + guild_id=int(self.id), + days=days, + include_roles=_roles, + ) + + return res.get("pruned") + async def get_emoji( self, emoji_id: int,