Skip to content

Commit

Permalink
Ability to change/set the banner of the bot.
Browse files Browse the repository at this point in the history
Added "banner" to the edit function.

Till now the official discord docs are not updated, but the code is working.

ref: discord/discord-api-docs#6710

Signed-off-by: Brandon <[email protected]>
  • Loading branch information
Braandn committed Mar 15, 2024
1 parent 7c06892 commit 8bdcaf7
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions discord/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,20 @@ def _update(self, data: UserPayload) -> None:

# TODO: Username might not be able to edit anymore.
async def edit(
self, *, username: str = MISSING, avatar: bytes = MISSING
self, *, username: str = MISSING, avatar: bytes = MISSING, banner: bytes = MISSING
) -> ClientUser:
"""|coro|
Edits the current profile of the client.
.. note::
To upload an avatar, a :term:`py:bytes-like object` must be passed in that
To upload an avatar or banner, a :term:`py:bytes-like object` must be passed in that
represents the image being uploaded. If this is done through a file
then the file must be opened via ``open('some_filename', 'rb')`` and
the :term:`py:bytes-like object` is given through the use of ``fp.read()``.
The only image formats supported for uploading is JPEG and PNG.
The only image formats supported for uploading is JPEG and PNG and GIF.
.. versionchanged:: 2.0
The edit is no longer in-place, instead the newly edited client user is returned.
Expand All @@ -447,6 +447,9 @@ async def edit(
avatar: :class:`bytes`
A :term:`py:bytes-like object` representing the image to upload.
Could be ``None`` to denote no avatar.
banner: :class:`bytes`
A :term:`py:bytes-like object` representing the image to upload.
Could be ``None`` to denote no banner.
Returns
-------
Expand All @@ -458,7 +461,7 @@ async def edit(
HTTPException
Editing your profile failed.
InvalidArgument
Wrong image format passed for ``avatar``.
Wrong image format passed for ``avatar`` or ``banner``.
"""
payload: dict[str, Any] = {}
if username is not MISSING:
Expand All @@ -469,6 +472,11 @@ async def edit(
elif avatar is not MISSING:
payload["avatar"] = _bytes_to_base64_data(avatar)

if banner is None:
payload["banner"] = None
elif banner is not MISSING:
payload["banner"] = _bytes_to_base64_data(banner)

data: UserPayload = await self._state.http.edit_profile(payload)
return ClientUser(state=self._state, data=data)

Expand Down

0 comments on commit 8bdcaf7

Please sign in to comment.