From c5baf6b9bfcb338a1e748718aa404807dd6a2e3f Mon Sep 17 00:00:00 2001 From: grey-cat-1908 Date: Tue, 5 Apr 2022 22:59:38 +0300 Subject: [PATCH] thread add, remove user method --- melisa/models/guild/channel.py | 58 ++++++++++++++++++++++++++++++++-- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/melisa/models/guild/channel.py b/melisa/models/guild/channel.py index 31a4e35..f92535c 100644 --- a/melisa/models/guild/channel.py +++ b/melisa/models/guild/channel.py @@ -311,9 +311,9 @@ class MessageableChannel(Channel): self, limit: int = 50, *, - before: Optional[Union[int, str, Snowflake]] = None, - after: Optional[Union[int, str, Snowflake]] = None, - around: Optional[Union[int, str, Snowflake]] = None, + before: Optional[Union[int, Snowflake]] = None, + after: Optional[Union[int, Snowflake]] = None, + around: Optional[Union[int, Snowflake]] = None, ) -> AsyncIterator[Dict[str, Any]]: """|coro| @@ -629,6 +629,58 @@ class TextChannel(MessageableChannel): class Thread(MessageableChannel): """A subclass of ``Channel`` for threads with all the same attributes.""" + async def add_user( + self, + user_id: Union[int, Snowflake] + ) -> None: + """|coro| + + Adds a user to this thread. + + You must have ``SEND_MESSAGES`` permission to add a user to a public thread. + If the thread is private then ``SEND_MESSAGES`` and either ``CREATE_PRIVATE_THREADS`` + or manage_messages permissions is required to add a user to the thread. + + Parameters + ---------- + user_id: Union[int, :class:`~melisa.utils.Snowflake`] + Id of user to add to the thread. + + Raises + ------- + HTTPException + The request to perform the action failed with other http exception. + ForbiddenError + You do not have permissions to add the user to the thread. + """ + + await self._http.put(f"channels/{self.id}/thread-members/{user_id}") + + async def remove_user( + self, + user_id: Union[int, Snowflake] + ) -> None: + """|coro| + + Removes a user from this thread. + + You must have ``MANAGE_THREADS`` or be the creator of the thread to remove a user. + + Parameters + ---------- + user_id: Union[int, :class:`~melisa.utils.Snowflake`] + Id of user to add to the thread. + + Raises + ------- + HTTPException + The request to perform the action failed with other http exception. + ForbiddenError + You do not have permissions to add the user to the thread. + """ + + await self._http.delete(f"channels/{self.id}/thread-members/{user_id}") + @dataclass(repr=False) class ThreadsList(APIModelBase):