Remove in-place edits and return fresh instances instead

Fixes #4098
This commit is contained in:
Rapptz
2021-08-23 23:46:50 -04:00
parent 9d4fa0341e
commit 490bbffc93
15 changed files with 251 additions and 82 deletions

View File

@ -349,7 +349,7 @@ class ClientUser(BaseUser):
self._flags = data.get('flags', 0)
self.mfa_enabled = data.get('mfa_enabled', False)
async def edit(self, *, username: str = MISSING, avatar: bytes = MISSING) -> None:
async def edit(self, *, username: str = MISSING, avatar: bytes = MISSING) -> ClientUser:
"""|coro|
Edits the current profile of the client.
@ -363,6 +363,9 @@ class ClientUser(BaseUser):
The only image formats supported for uploading is JPEG and PNG.
.. versionchanged:: 2.0
The edit is no longer in-place, instead the newly edited client user is returned.
Parameters
-----------
username: :class:`str`
@ -377,6 +380,11 @@ class ClientUser(BaseUser):
Editing your profile failed.
InvalidArgument
Wrong image format passed for ``avatar``.
Returns
---------
:class:`ClientUser`
The newly edited client user.
"""
payload: Dict[str, Any] = {}
if username is not MISSING:
@ -386,7 +394,7 @@ class ClientUser(BaseUser):
payload['avatar'] = _bytes_to_base64_data(avatar)
data: UserPayload = await self._state.http.edit_profile(payload)
self._update(data)
return ClientUser(state=self._state, data=data)
class User(BaseUser, discord.abc.Messageable):