Skip to content
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

feat: support banner parameter in ClientUser.edit #1165

Merged
merged 3 commits into from
Apr 15, 2024
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
1 change: 1 addition & 0 deletions changelog/1165.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``banner`` parameter to :meth:`ClientUser.edit`.
23 changes: 19 additions & 4 deletions disnake/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ def _update(self, data: UserPayload) -> None:
self.mfa_enabled = data.get("mfa_enabled", False)

async def edit(
self, *, username: str = MISSING, avatar: Optional[AssetBytes] = MISSING
self,
*,
username: str = MISSING,
avatar: Optional[AssetBytes] = MISSING,
banner: Optional[AssetBytes] = MISSING,
) -> ClientUser:
"""|coro|

Expand All @@ -384,16 +388,24 @@ async def edit(
.. versionchanged:: 2.5
Now accepts various resource types in addition to :class:`bytes`.

banner: Optional[|resource_type|]
A :term:`py:bytes-like object` or asset representing the image to upload.
Could be ``None`` to denote no banner.

Only JPG, PNG, WEBP (static), and GIF (static/animated) images are supported.

.. versionadded:: 2.10

Raises
------
NotFound
The ``avatar`` asset couldn't be found.
The ``avatar`` or ``banner`` asset couldn't be found.
HTTPException
Editing your profile failed.
TypeError
The ``avatar`` asset is a lottie sticker (see :func:`Sticker.read`).
The ``avatar`` or ``banner`` asset is a lottie sticker (see :func:`Sticker.read`).
ValueError
Wrong image format passed for ``avatar``.
Wrong image format passed for ``avatar`` or ``banner``.

Returns
-------
Expand All @@ -407,6 +419,9 @@ async def edit(
if avatar is not MISSING:
payload["avatar"] = await _assetbytes_to_base64_data(avatar)

if banner is not MISSING:
payload["banner"] = await _assetbytes_to_base64_data(banner)

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

Expand Down
Loading