From 4675c6ce49edbc15bebce5ff1446f9aa8d6a4faa Mon Sep 17 00:00:00 2001 From: Lala Sabathil Date: Mon, 1 May 2023 18:36:24 +0200 Subject: [PATCH] fix: Reflect api for bans correctly (#1922) Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Co-authored-by: plun1331 <49261529+plun1331@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- CHANGELOG.md | 2 ++ discord/guild.py | 22 ++++++++++++---------- discord/iterators.py | 6 ------ 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ea9772dd19..31ff4a2666 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -80,6 +80,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2000](https://github.com/Pycord-Development/pycord/pull/2000)) - Fixed `TypeError` in AutoModRule. ([#2029](https://github.com/Pycord-Development/pycord/pull/2029)) +- Reflecting the api for gettings bans correctly. + ([#1922](https://github.com/Pycord-Development/pycord/pull/1922)) ## [2.4.1] - 2023-03-20 diff --git a/discord/guild.py b/discord/guild.py index 718164aa8e..8d4517e5fc 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -2116,13 +2116,19 @@ async def fetch_channel(self, channel_id: int, /) -> GuildChannel | Thread: def bans( self, limit: int | None = None, - before: SnowflakeTime | None = None, - after: SnowflakeTime | None = None, + before: Snowflake | None = None, + after: Snowflake | None = None, ) -> BanIterator: """|coro| Retrieves an :class:`.AsyncIterator` that enables receiving the guild's bans. In order to use this, you must have the :attr:`~Permissions.ban_members` permission. + Users will always be returned in ascending order sorted by user ID. + If both the ``before`` and ``after`` parameters are provided, only before is respected. + + .. versionchanged:: 2.5 + The ``before``. and ``after`` parameters were changed. They are now of the type :class:`.abc.Snowflake` instead of + `SnowflakeTime` to comply with the discord api. .. versionchanged:: 2.0 The ``limit``, ``before``. and ``after`` parameters were added. Now returns a :class:`.BanIterator` instead @@ -2134,14 +2140,10 @@ def bans( ---------- limit: Optional[:class:`int`] The number of bans to retrieve. Defaults to 1000. - before: Optional[Union[:class:`.abc.Snowflake`, :class:`datetime.datetime`]] - Retrieve bans before this date or object. - If a datetime is provided, it is recommended to use a UTC aware datetime. - If the datetime is naive, it is assumed to be local time. - after: Optional[Union[:class:`.abc.Snowflake`, :class:`datetime.datetime`]] - Retrieve bans after this date or object. - If a datetime is provided, it is recommended to use a UTC aware datetime. - If the datetime is naive, it is assumed to be local time. + before: Optional[:class:`.abc.Snowflake`] + Retrieve bans before the given user. + after: Optional[:class:`.abc.Snowflake`] + Retrieve bans after the given user. Yields ------ diff --git a/discord/iterators.py b/discord/iterators.py index f4ec6cda28..78edb7570d 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -689,12 +689,6 @@ def create_member(self, data): class BanIterator(_AsyncIterator["BanEntry"]): def __init__(self, guild, limit=None, before=None, after=None): - if isinstance(after, datetime.datetime): - after = Object(id=time_snowflake(after, high=True)) - - if isinstance(before, datetime.datetime): - before = Object(id=time_snowflake(before, high=True)) - self.guild = guild self.limit = limit self.after = after