mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-10-18 20:14:42 +00:00
Support new fields in Modify Current Member
This commit is contained in:
@@ -1136,18 +1136,15 @@ class HTTPClient:
|
|||||||
def edit_profile(self, payload: Dict[str, Any]) -> Response[user.User]:
|
def edit_profile(self, payload: Dict[str, Any]) -> Response[user.User]:
|
||||||
return self.request(Route('PATCH', '/users/@me'), json=payload)
|
return self.request(Route('PATCH', '/users/@me'), json=payload)
|
||||||
|
|
||||||
def change_my_nickname(
|
def edit_my_member(
|
||||||
self,
|
self,
|
||||||
guild_id: Snowflake,
|
guild_id: Snowflake,
|
||||||
nickname: str,
|
|
||||||
*,
|
*,
|
||||||
reason: Optional[str] = None,
|
reason: Optional[str] = None,
|
||||||
) -> Response[member.Nickname]:
|
**fields: Any,
|
||||||
r = Route('PATCH', '/guilds/{guild_id}/members/@me/nick', guild_id=guild_id)
|
) -> Response[member.MemberWithUser]:
|
||||||
payload = {
|
r = Route('PATCH', '/guilds/{guild_id}/members/@me', guild_id=guild_id)
|
||||||
'nick': nickname,
|
return self.request(r, json=fields, reason=reason)
|
||||||
}
|
|
||||||
return self.request(r, json=payload, reason=reason)
|
|
||||||
|
|
||||||
def change_nickname(
|
def change_nickname(
|
||||||
self,
|
self,
|
||||||
|
@@ -815,12 +815,22 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
voice_channel: Optional[VocalGuildChannel] = MISSING,
|
voice_channel: Optional[VocalGuildChannel] = MISSING,
|
||||||
timed_out_until: Optional[datetime.datetime] = MISSING,
|
timed_out_until: Optional[datetime.datetime] = MISSING,
|
||||||
bypass_verification: bool = MISSING,
|
bypass_verification: bool = MISSING,
|
||||||
|
avatar: Optional[bytes] = MISSING,
|
||||||
|
banner: Optional[bytes] = MISSING,
|
||||||
|
bio: Optional[str] = MISSING,
|
||||||
reason: Optional[str] = None,
|
reason: Optional[str] = None,
|
||||||
) -> Optional[Member]:
|
) -> Optional[Member]:
|
||||||
"""|coro|
|
"""|coro|
|
||||||
|
|
||||||
Edits the member's data.
|
Edits the member's data.
|
||||||
|
|
||||||
|
.. note::
|
||||||
|
|
||||||
|
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()``.
|
||||||
|
|
||||||
Depending on the parameter passed, this requires different permissions listed below:
|
Depending on the parameter passed, this requires different permissions listed below:
|
||||||
|
|
||||||
+---------------------+---------------------------------------+
|
+---------------------+---------------------------------------+
|
||||||
@@ -876,6 +886,20 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
Indicates if the member should be allowed to bypass the guild verification requirements.
|
Indicates if the member should be allowed to bypass the guild verification requirements.
|
||||||
|
|
||||||
.. versionadded:: 2.2
|
.. versionadded:: 2.2
|
||||||
|
avatar: Optional[:class:`bytes`]
|
||||||
|
A :term:`py:bytes-like object` representing the image to upload. Could be ``None`` to denote no avatar.
|
||||||
|
Only image formats supported for uploading are JPEG, PNG, GIF, and WEBP.
|
||||||
|
This can only be set when editing the bot's own member.
|
||||||
|
.. versionadded:: 2.7
|
||||||
|
banner: Optional[:class:`bytes`]
|
||||||
|
A :term:`py:bytes-like object` representing the image to upload. Could be ``None`` to denote no banner.
|
||||||
|
Only image formats supported for uploading are JPEG, PNG, GIF and WEBP..
|
||||||
|
This can only be set when editing the bot's own member.
|
||||||
|
.. versionadded:: 2.7
|
||||||
|
bio: Optional[:class:`str`]
|
||||||
|
The new bio for the member. Use ``None`` to remove the bio.
|
||||||
|
This can only be set when editing the bot's own member.
|
||||||
|
.. versionadded:: 2.7
|
||||||
|
|
||||||
reason: Optional[:class:`str`]
|
reason: Optional[:class:`str`]
|
||||||
The reason for editing this member. Shows up on the audit log.
|
The reason for editing this member. Shows up on the audit log.
|
||||||
@@ -888,6 +912,9 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
The operation failed.
|
The operation failed.
|
||||||
TypeError
|
TypeError
|
||||||
The datetime object passed to ``timed_out_until`` was not timezone-aware.
|
The datetime object passed to ``timed_out_until`` was not timezone-aware.
|
||||||
|
ValueError
|
||||||
|
You tried to edit the bio, avatar or banner of a member that is not the bot's own member.
|
||||||
|
Or the wrong image format passed for ``avatar`` or ``banner``.
|
||||||
|
|
||||||
Returns
|
Returns
|
||||||
--------
|
--------
|
||||||
@@ -899,14 +926,33 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
guild_id = self.guild.id
|
guild_id = self.guild.id
|
||||||
me = self._state.self_id == self.id
|
me = self._state.self_id == self.id
|
||||||
payload: Dict[str, Any] = {}
|
payload: Dict[str, Any] = {}
|
||||||
|
self_payload: Dict[str, Any] = {}
|
||||||
|
|
||||||
if nick is not MISSING:
|
if nick is not MISSING:
|
||||||
nick = nick or ''
|
nick = nick or ''
|
||||||
if me:
|
if me:
|
||||||
await http.change_my_nickname(guild_id, nick, reason=reason)
|
self_payload['nick'] = nick
|
||||||
else:
|
else:
|
||||||
payload['nick'] = nick
|
payload['nick'] = nick
|
||||||
|
|
||||||
|
if avatar is not MISSING:
|
||||||
|
if avatar is None:
|
||||||
|
self_payload['avatar'] = None
|
||||||
|
else:
|
||||||
|
self_payload['avatar'] = utils._bytes_to_base64_data(avatar)
|
||||||
|
|
||||||
|
if banner is not MISSING:
|
||||||
|
if banner is None:
|
||||||
|
self_payload['banner'] = None
|
||||||
|
else:
|
||||||
|
self_payload['banner'] = utils._bytes_to_base64_data(banner)
|
||||||
|
|
||||||
|
if bio is not MISSING:
|
||||||
|
self_payload['bio'] = bio or ''
|
||||||
|
|
||||||
|
if not me and self_payload:
|
||||||
|
raise ValueError("Editing the bio, avatar or banner is only for the bot's own member.")
|
||||||
|
|
||||||
if deafen is not MISSING:
|
if deafen is not MISSING:
|
||||||
payload['deaf'] = deafen
|
payload['deaf'] = deafen
|
||||||
|
|
||||||
@@ -954,6 +1000,11 @@ class Member(discord.abc.Messageable, _UserTag):
|
|||||||
|
|
||||||
if payload:
|
if payload:
|
||||||
data = await http.edit_member(guild_id, self.id, reason=reason, **payload)
|
data = await http.edit_member(guild_id, self.id, reason=reason, **payload)
|
||||||
|
elif self_payload:
|
||||||
|
data = await http.edit_my_member(guild_id, reason=reason, **self_payload)
|
||||||
|
else:
|
||||||
|
return None
|
||||||
|
|
||||||
return Member(data=data, guild=self.guild, state=self._state)
|
return Member(data=data, guild=self.guild, state=self._state)
|
||||||
|
|
||||||
async def request_to_speak(self) -> None:
|
async def request_to_speak(self) -> None:
|
||||||
|
Reference in New Issue
Block a user