Skip to content

Commit 44448e3

Browse files
kytewarepre-commit-ci[bot]EepyElvyra
authored
feat: add new guild helper methods (#647)
* feat: two new guild methods * feat: added new guild methods to pyi * fix: corrected http method name * ci: correct from checks. * fix: add typehint for get_list_of_member returns Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * fix: add typehint for search_members method return Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * feat: add typehint for search_member return in main file Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * fix: add typehint for get_list_of_member returns in main file Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * feat: allow member to be used as an input for get_list_of_members very cool idea Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * doc: specify that Member objects should be use in after param Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * doc: change docstring to allow for Member objects and int to be used Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * fix: account for errors with MISSING, make ids and Member objects both function this is some voodoo Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * doc: make Member and int usage in get_list_of_members and default to MISSING Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com> * doc: add return info to get_list_of_members * doc: add return info to docstring search_members * doc: properly closed bracket * fix: properly closed brackets * ci: correct from checks. Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: EdVraz <88881326+EdVraz@users.noreply.github.com>
1 parent c68ebe1 commit 44448e3

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

interactions/api/models/guild.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1546,6 +1546,50 @@ async def delete_emoji(
15461546
reason=reason,
15471547
)
15481548

1549+
async def get_list_of_members(
1550+
self,
1551+
limit: Optional[int] = 1,
1552+
after: Optional[Union[Member, int]] = MISSING,
1553+
) -> List[Member]:
1554+
"""
1555+
Lists the members of a guild.
1556+
1557+
:param limit?: How many members to get from the API. Max is 1000.
1558+
:type limit: Optional[int]
1559+
:param after?: Get only Members after this member.
1560+
:type after: Optional[Union[Member, int]]
1561+
:return: A list of members
1562+
:rtype: List[Member]
1563+
"""
1564+
if not self._client:
1565+
raise AttributeError("HTTPClient not found!")
1566+
if after is not MISSING:
1567+
_after = int(after.id) if not isinstance(after, int) else after
1568+
else:
1569+
_after = None
1570+
res = await self._client.get_list_of_members(
1571+
guild_id=int(self.id), limit=limit, after=_after
1572+
)
1573+
return [Member(**member, _client=self._client) for member in res]
1574+
1575+
async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Member]:
1576+
"""
1577+
Search the guild for members whose username or nickname starts with provided string.
1578+
1579+
:param query: The string to search for
1580+
:type query: str
1581+
:param limit?: The number of members to return.
1582+
:type limit: Optional[int]
1583+
:return: A list of matching members
1584+
:rtype: List[Member]
1585+
"""
1586+
if not self._client:
1587+
raise AttributeError("HTTPClient not found!")
1588+
res = await self._client.search_guild_members(
1589+
guild_id=int(self.id), query=query, limit=limit
1590+
)
1591+
return [Member(**member, _client=self._client) for member in res]
1592+
15491593

15501594
class GuildPreview(DictSerializerMixin):
15511595
"""

interactions/api/models/guild.pyi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,16 @@ class Guild(DictSerializerMixin):
394394
emoji: Union[Emoji, int],
395395
reason: Optional[str] = None,
396396
) -> None: ...
397+
async def get_list_of_members(
398+
self,
399+
limit: Optional[int] = 1,
400+
after: Optional[Union[Member, int]] = MISSING,
401+
) -> List[Member]: ...
402+
async def search_members(
403+
self,
404+
query: str,
405+
limit: Optional[int] = 1
406+
) -> List[Member]: ...
397407

398408
class GuildPreview(DictSerializerMixin):
399409
_json: dict

0 commit comments

Comments
 (0)