From 68453c7bed7c18682c6146c50e011693cb99fe72 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Wed, 18 Aug 2021 01:57:07 -0400 Subject: [PATCH] Add Thread.members and Thread.fetch_members --- discord/threads.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/discord/threads.py b/discord/threads.py index a8d33f671..0550916c5 100644 --- a/discord/threads.py +++ b/discord/threads.py @@ -217,6 +217,16 @@ class Thread(Messageable, Hashable): """:class:`str`: The string that allows you to mention the thread.""" return f'<#{self.id}>' + @property + def members(self) -> List[ThreadMember]: + """List[:class:`ThreadMember`]: A list of thread members in this thread. + + This requires :attr:`Intents.members` to be properly filled. Most of the time however, + this data is not provided by the gateway and a call to :meth:`fetch_members` is + needed. + """ + return list(self._members.values()) + @property def last_message(self) -> Optional[Message]: """Fetches the last message from this channel in cache. @@ -636,6 +646,28 @@ class Thread(Messageable, Hashable): """ await self._state.http.remove_user_from_thread(self.id, user.id) + async def fetch_members(self) -> List[ThreadMember]: + """|coro| + + Retrieves all :class:`ThreadMember` that are in this thread. + + This requires :attr:`Intents.members` to get information about members + other than yourself. + + Raises + ------- + HTTPException + Retrieving the members failed. + + Returns + -------- + List[:class:`ThreadMember`] + All thread members in the thread. + """ + + members = await self._state.http.get_thread_members(self.id) + return [ThreadMember(parent=self, data=data) for data in members] + async def delete(self): """|coro|