diff --git a/interactions/api/models/channel.py b/interactions/api/models/channel.py index 3ed721c64..2716e9729 100644 --- a/interactions/api/models/channel.py +++ b/interactions/api/models/channel.py @@ -618,6 +618,9 @@ async def purge( ) -> List["Message"]: # noqa """ Purges a given amount of messages from a channel. You can specify a check function to exclude specific messages. + + .. warning:: Calling this method can lead to rate-limits when purging higher amounts of messages. + .. code-block:: python def check_pinned(message): return not message.pinned # This returns `True` only if the message is the message is not pinned diff --git a/interactions/api/models/guild.py b/interactions/api/models/guild.py index 2f2476bb5..6c5ede968 100644 --- a/interactions/api/models/guild.py +++ b/interactions/api/models/guild.py @@ -699,7 +699,7 @@ async def create_channel( :param topic?: The topic of that channel :type topic: Optional[str] :param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel - :type bitrate Optional[int] + :type bitrate: Optional[int] :param user_limit?: (voice channel only) Maximum amount of users in the channel :type user_limit: Optional[int] :param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600) @@ -791,7 +791,7 @@ async def modify_channel( :param topic?: The topic of that channel, defaults to the current value of the channel :type topic: Optional[str] :param bitrate?: (voice channel only) The bitrate (in bits) of the voice channel, defaults to the current value of the channel - :type bitrate Optional[int] + :type bitrate: Optional[int] :param user_limit?: (voice channel only) Maximum amount of users in the channel, defaults to the current value of the channel :type user_limit: Optional[int] :param rate_limit_per_use?: Amount of seconds a user has to wait before sending another message (0-21600), defaults to the current value of the channel @@ -1600,6 +1600,34 @@ async def search_members(self, query: str, limit: Optional[int] = 1) -> List[Mem ) return [Member(**member, _client=self._client) for member in res] + async def get_all_members(self) -> List[Member]: + """ + Gets all members of a guild. + + .. warning:: Calling this method can lead to rate-limits in larger guilds. + + :return: Returns a list of all members of the guild + :rtype: List[Member] + """ + if not self._client: + raise AttributeError("HTTPClient not found!") + + _all_members: List[dict] = [] + _last_member: Member + _members: List[dict] = await self._client.get_list_of_members( + guild_id=int(self.id), limit=100 + ) + if len(_members) == 100: + while len(_members) >= 100: + _all_members.extend(_members) + _last_member = Member(**_members[-1]) + _members = await self._client.get_list_of_members( + guild_id=int(self.id), limit=100, after=int(_last_member.id) + ) + _all_members.extend(_members) + + return [Member(**_, _client=self._client) for _ in _all_members] + class GuildPreview(DictSerializerMixin): """ diff --git a/interactions/api/models/guild.pyi b/interactions/api/models/guild.pyi index 69bbea3bd..21bd0a35e 100644 --- a/interactions/api/models/guild.pyi +++ b/interactions/api/models/guild.pyi @@ -409,6 +409,7 @@ class Guild(DictSerializerMixin): query: str, limit: Optional[int] = 1 ) -> List[Member]: ... + async def get_all_members(self) -> List[Member]: ... class GuildPreview(DictSerializerMixin): _json: dict