Skip to content

Commit f4cf58c

Browse files
committed
Add support for new current member fields
discord/discord-api-docs#7807
1 parent 3fd5d70 commit f4cf58c

File tree

2 files changed

+64
-40
lines changed

2 files changed

+64
-40
lines changed

discord/http.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1020,38 +1020,6 @@ def guild_voice_state(
10201020
def edit_profile(self, payload: dict[str, Any]) -> Response[user.User]:
10211021
return self.request(Route("PATCH", "/users/@me"), json=payload)
10221022

1023-
def change_my_nickname(
1024-
self,
1025-
guild_id: Snowflake,
1026-
nickname: str,
1027-
*,
1028-
reason: str | None = None,
1029-
) -> Response[member.Nickname]:
1030-
r = Route("PATCH", "/guilds/{guild_id}/members/@me", guild_id=guild_id)
1031-
payload = {
1032-
"nick": nickname,
1033-
}
1034-
return self.request(r, json=payload, reason=reason)
1035-
1036-
def change_nickname(
1037-
self,
1038-
guild_id: Snowflake,
1039-
user_id: Snowflake,
1040-
nickname: str,
1041-
*,
1042-
reason: str | None = None,
1043-
) -> Response[member.Member]:
1044-
r = Route(
1045-
"PATCH",
1046-
"/guilds/{guild_id}/members/{user_id}",
1047-
guild_id=guild_id,
1048-
user_id=user_id,
1049-
)
1050-
payload = {
1051-
"nick": nickname,
1052-
}
1053-
return self.request(r, json=payload, reason=reason)
1054-
10551023
def edit_my_voice_state(
10561024
self, guild_id: Snowflake, payload: dict[str, Any]
10571025
) -> Response[None]:
@@ -1077,12 +1045,7 @@ def edit_member(
10771045
reason: str | None = None,
10781046
**fields: Any,
10791047
) -> Response[member.MemberWithUser]:
1080-
r = Route(
1081-
"PATCH",
1082-
"/guilds/{guild_id}/members/{user_id}",
1083-
guild_id=guild_id,
1084-
user_id=user_id,
1085-
)
1048+
r = Route("PATCH", "/guilds/{guild_id}/members/{user_id}", guild_id=guild_id, user_id=user_id)
10861049
return self.request(r, json=fields, reason=reason)
10871050

10881051
# Channel management

discord/member.py

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
from .permissions import Permissions
4545
from .user import BaseUser, User, _UserTag
4646
from .utils import MISSING
47+
from .errors import InvalidArgument
4748

4849
__all__ = (
4950
"VoiceState",
@@ -769,6 +770,9 @@ async def edit(
769770
reason: str | None = None,
770771
communication_disabled_until: datetime.datetime | None = MISSING,
771772
bypass_verification: bool | None = MISSING,
773+
banner: bytes | None = MISSING,
774+
avatar: bytes | None = MISSING,
775+
bio: str | None = MISSING,
772776
) -> Member | None:
773777
"""|coro|
774778
@@ -804,6 +808,14 @@ async def edit(
804808
805809
- Client has ALL THREE of :attr:`Permissions.moderate_members`, :attr:`Permissions.kick_members`, and :attr:`Permissions.ban_members`
806810
811+
.. note::
812+
813+
The following parameters are only available when editing the bot's own member:
814+
815+
- ``avatar``
816+
- ``banner``
817+
- ``bio``
818+
807819
All parameters are optional.
808820
809821
.. versionchanged:: 1.1
@@ -841,6 +853,26 @@ async def edit(
841853
Indicates if the member should bypass the guild's verification requirements.
842854
843855
.. versionadded:: 2.6
856+
banner: Optional[:class:`bytes`]
857+
A :term:`py:bytes-like object` representing the banner.
858+
Could be ``None`` to denote removal of the banner.
859+
860+
This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
861+
862+
.. versionadded:: 2.7
863+
avatar: Optional[:class:`bytes`]
864+
A :term:`py:bytes-like object` representing the avatar.
865+
Could be ``None`` to denote removal of the avatar.
866+
867+
This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
868+
869+
.. versionadded:: 2.7
870+
bio: Optional[:class:`str`]
871+
The new bio for the member. Could be ``None`` to denote removal of the bio.
872+
873+
This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
874+
875+
.. versionadded:: 2.7
844876
845877
Returns
846878
-------
@@ -854,16 +886,19 @@ async def edit(
854886
You do not have the proper permissions to the action requested.
855887
HTTPException
856888
The operation failed.
889+
InvalidArgument
890+
You tried to edit the avatar, banner, or bio of a member that is not the bot.
857891
"""
858892
http = self._state.http
859893
guild_id = self.guild.id
860894
me = self._state.self_id == self.id
861895
payload: dict[str, Any] = {}
896+
bot_payload: dict[str, Any] = {}
862897

863898
if nick is not MISSING:
864899
nick = nick or ""
865900
if me:
866-
await http.change_my_nickname(guild_id, nick, reason=reason)
901+
bot_payload["nick"] = nick
867902
else:
868903
payload["nick"] = nick
869904

@@ -910,9 +945,35 @@ async def edit(
910945
flags.bypasses_verification = bypass_verification
911946
payload["flags"] = flags.value
912947

948+
949+
if avatar is not MISSING:
950+
if avatar is None:
951+
bot_payload["avatar"] = None
952+
else:
953+
bot_payload["avatar"] = utils._bytes_to_base64_data(avatar)
954+
955+
if banner is not MISSING:
956+
if banner is None:
957+
bot_payload["banner"] = None
958+
else:
959+
bot_payload["banner"] = utils._bytes_to_base64_data(banner)
960+
961+
if bio is not MISSING:
962+
bot_payload["bio"] = bio or ""
963+
964+
if bot_payload and not me:
965+
raise InvalidArgument("Can only edit avatar, banner, or bio for the bot's member.")
966+
967+
if not payload and not bot_payload:
968+
return None
969+
913970
if payload:
914971
data = await http.edit_member(guild_id, self.id, reason=reason, **payload)
915-
return Member(data=data, guild=self.guild, state=self._state)
972+
else:
973+
data = await http.edit_member(guild_id, "@me", reason=reason, **bot_payload)
974+
975+
return Member(data=data, guild=self.guild, state=self._state)
976+
916977

917978
async def timeout(
918979
self, until: datetime.datetime | None, *, reason: str | None = None

0 commit comments

Comments
 (0)