From 93791d2ba1ba0372893fa13904eb2aa73a2678d5 Mon Sep 17 00:00:00 2001 From: dolfies Date: Sun, 19 Jun 2022 18:15:20 -0400 Subject: [PATCH] Implement silent group leaving --- discord/channel.py | 18 ++++++++++++++---- discord/http.py | 10 ++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/discord/channel.py b/discord/channel.py index 90ba6945a..b13e03719 100644 --- a/discord/channel.py +++ b/discord/channel.py @@ -2717,7 +2717,7 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, Hashable): # The payload will always be the proper channel payload return self.__class__(me=self.me, state=self._state, data=data) # type: ignore - async def leave(self) -> None: + async def leave(self, *, silent: bool = False) -> None: """|coro| Leave the group. @@ -2726,14 +2726,19 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, Hashable): There is an alias for this called :func:`close`. + Parameters + ----------- + silent: :class:`bool` + Whether to leave the group without sending a leave message. + Raises ------- HTTPException Leaving the group failed. """ - await self._state.http.delete_channel(self.id) + await self._state.http.delete_channel(self.id, silent=silent) - async def close(self) -> None: + async def close(self, *, silent: bool = False) -> None: """|coro| Leave the group. @@ -2742,12 +2747,17 @@ class GroupChannel(discord.abc.Messageable, discord.abc.Connectable, Hashable): This is an alias of :func:`leave`. + Parameters + ----------- + silent: :class:`bool` + Whether to leave the group without sending a leave message. + Raises ------- HTTPException Leaving the group failed. """ - await self.leave() + await self.leave(silent=silent) async def create_invite(self, *, max_age: int = 86400) -> Invite: """|coro| diff --git a/discord/http.py b/discord/http.py index 9ba0fa6b5..5267b2d75 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1062,8 +1062,14 @@ class HTTPClient: return self.request(Route('POST', '/guilds/{guild_id}/channels', guild_id=guild_id), json=payload, reason=reason) - def delete_channel(self, channel_id: Snowflake, *, reason: Optional[str] = None) -> Response[None]: - return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), reason=reason) + def delete_channel( + self, channel_id: Snowflake, *, reason: Optional[str] = None, silent: bool = MISSING + ) -> Response[channel.Channel]: + params = {} + if silent is not MISSING: + params['silent'] = str(silent).lower() + + return self.request(Route('DELETE', '/channels/{channel_id}', channel_id=channel_id), params=params, reason=reason) # Thread management