diff --git a/melisa/models/guild/guild.py b/melisa/models/guild/guild.py index 28a3243..25cf4a0 100644 --- a/melisa/models/guild/guild.py +++ b/melisa/models/guild/guild.py @@ -5,7 +5,7 @@ from __future__ import annotations from dataclasses import dataclass from enum import IntEnum -from typing import List, Any, Optional, overload, Dict, TYPE_CHECKING +from typing import List, Any, Optional, overload, Dict, TYPE_CHECKING, Union from .channel import ( ThreadsList, @@ -575,6 +575,38 @@ class Guild(APIModelBase): await self._http.get(f"/guilds/{self.id}/threads/active") ) + async def unban( + self, + user_id: Union[Snowflake, str, int], + *, + reason: Optional[str] = None, + ): + """|coro| + + Remove the ban for a user. + + **Required permissions:** ``BAN_MEMBERS`` + + Parameters + ---------- + user_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + Id of user to operate with. + reason: Optional[:class:`str`] + The reason of the action. + + Raises + ------- + HTTPException + The request to perform the action failed with other http exception. + ForbiddenError + You do not have proper permissions to do the actions required. + BadRequestError + You provided a wrong guild, user or something else + Or if the user is not banned + """ + + await self._client.rest.remove_guild_ban(self.id, user_id, reason=reason) + @dataclass(repr=False) class UnavailableGuild(APIModelBase): diff --git a/melisa/rest.py b/melisa/rest.py index f6f067e..e02471f 100644 --- a/melisa/rest.py +++ b/melisa/rest.py @@ -535,6 +535,44 @@ class RESTApp: headers={"X-Audit-Log-Reason": reason}, ) + async def remove_guild_ban( + self, + guild_id: Union[Snowflake, str, int], + user_id: Union[Snowflake, str, int], + *, + reason: Optional[str] = None, + ): + """|coro| + + [**REST API**] Remove the ban for a user. + + **Required permissions:** ``BAN_MEMBERS`` + + Parameters + ---------- + guild_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + Id of guild where we will remove ban for member + user_id: Union[:class:`int`, :class:`str`, :class:`~.melisa.utils.snowflake.Snowflake`] + Id of user to operate with. + reason: Optional[:class:`str`] + The reason of the action. + + Raises + ------- + HTTPException + The request to perform the action failed with other http exception. + ForbiddenError + You do not have proper permissions to do the actions required. + BadRequestError + You provided a wrong guild, user or something else + Or if the user is not banned + """ + + await self._http.delete( + f"guilds/{guild_id}/bans/{user_id}", + headers={"X-Audit-Log-Reason": reason}, + ) + async def add_guild_member_role( self, guild_id: Union[Snowflake, str, int],