Skip to content

Commit

Permalink
New delete_message_seconds parameter (Pycord-Development#1557)
Browse files Browse the repository at this point in the history
* chore: refactor bans

* refactor: use None for optional parameters

* refactor: just make delete_message_days deprecated

not aliased

Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Co-authored-by: Lala Sabathil <lala@pycord.dev>
  • Loading branch information
3 people authored Oct 1, 2022
1 parent 6c6505b commit 5b4e067
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
21 changes: 16 additions & 5 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -2933,8 +2933,9 @@ async def ban(
self,
user: Snowflake,
*,
delete_message_seconds: Optional[int] = None,
delete_message_days: Optional[int] = None,
reason: Optional[str] = None,
delete_message_days: Literal[0, 1, 2, 3, 4, 5, 6, 7] = 1,
) -> None:
"""|coro|
Expand All @@ -2949,9 +2950,13 @@ async def ban(
-----------
user: :class:`abc.Snowflake`
The user to ban from their guild.
delete_message_days: :class:`int`
The number of days worth of messages to delete from the user
in the guild. The minimum is 0 and the maximum is 7.
delete_message_seconds: Optional[:class:`int`]
The number of seconds worth of messages to delete from
the user in the guild. The minimum is 0 and the maximum
is 604800 (i.e. 7 days). The default is 0.
delete_message_days: Optional[:class:`int`]
***Deprecated parameter***, same as ``delete_message_seconds`` but
is used for days instead.
reason: Optional[:class:`str`]
The reason the user got banned.
Expand All @@ -2962,7 +2967,13 @@ async def ban(
HTTPException
Banning failed.
"""
await self._state.http.ban(user.id, self.id, delete_message_days, reason=reason)
if delete_message_seconds and delete_message_days:
raise TypeError("delete_message_seconds and delete_message_days are mutually exclusive.")

if not (0 <= delete_message_seconds <= 604800):
raise TypeError("delete_message_seconds must be between 0 and 604800 seconds.")

await self._state.http.ban(user.id, self.id, delete_message_seconds, delete_message_days, reason=reason)

async def unban(self, user: Snowflake, *, reason: Optional[str] = None) -> None:
"""|coro|
Expand Down
12 changes: 8 additions & 4 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,8 @@ def ban(
self,
user_id: Snowflake,
guild_id: Snowflake,
delete_message_days: int = 1,
delete_message_seconds: int = None,
delete_message_days: int = None,
reason: Optional[str] = None,
) -> Response[None]:
r = Route(
Expand All @@ -859,9 +860,12 @@ def ban(
guild_id=guild_id,
user_id=user_id,
)
params = {
"delete_message_days": delete_message_days,
}
params = {}

if delete_message_days:
params["delete_message_days"] = delete_message_days
elif delete_message_seconds:
params["delete_message_seconds"] = delete_message_seconds

return self.request(r, params=params, reason=reason)

Expand Down

0 comments on commit 5b4e067

Please sign in to comment.