Skip to content

fix!: Reflect the api for getting bans correctly #1922

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 19 commits into from
May 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 12 additions & 10 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
------
Expand Down
6 changes: 0 additions & 6 deletions discord/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down