39
39
from .asset import Asset
40
40
from .colour import Colour
41
41
from .enums import Status , try_enum
42
+ from .errors import InvalidArgument
42
43
from .flags import MemberFlags
43
44
from .object import Object
44
45
from .permissions import Permissions
@@ -769,6 +770,9 @@ async def edit(
769
770
reason : str | None = None ,
770
771
communication_disabled_until : datetime .datetime | None = MISSING ,
771
772
bypass_verification : bool | None = MISSING ,
773
+ banner : bytes | None = MISSING ,
774
+ avatar : bytes | None = MISSING ,
775
+ bio : str | None = MISSING ,
772
776
) -> Member | None :
773
777
"""|coro|
774
778
@@ -804,6 +808,14 @@ async def edit(
804
808
805
809
- Client has ALL THREE of :attr:`Permissions.moderate_members`, :attr:`Permissions.kick_members`, and :attr:`Permissions.ban_members`
806
810
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
+
807
819
All parameters are optional.
808
820
809
821
.. versionchanged:: 1.1
@@ -841,6 +853,26 @@ async def edit(
841
853
Indicates if the member should bypass the guild's verification requirements.
842
854
843
855
.. 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
844
876
845
877
Returns
846
878
-------
@@ -854,16 +886,19 @@ async def edit(
854
886
You do not have the proper permissions to the action requested.
855
887
HTTPException
856
888
The operation failed.
889
+ InvalidArgument
890
+ You tried to edit the avatar, banner, or bio of a member that is not the bot.
857
891
"""
858
892
http = self ._state .http
859
893
guild_id = self .guild .id
860
894
me = self ._state .self_id == self .id
861
895
payload : dict [str , Any ] = {}
896
+ bot_payload : dict [str , Any ] = {}
862
897
863
898
if nick is not MISSING :
864
899
nick = nick or ""
865
900
if me :
866
- await http . change_my_nickname ( guild_id , nick , reason = reason )
901
+ bot_payload [ " nick" ] = nick
867
902
else :
868
903
payload ["nick" ] = nick
869
904
@@ -910,9 +945,34 @@ async def edit(
910
945
flags .bypasses_verification = bypass_verification
911
946
payload ["flags" ] = flags .value
912
947
948
+ if avatar is not MISSING :
949
+ if avatar is None :
950
+ bot_payload ["avatar" ] = None
951
+ else :
952
+ bot_payload ["avatar" ] = utils ._bytes_to_base64_data (avatar )
953
+
954
+ if banner is not MISSING :
955
+ if banner is None :
956
+ bot_payload ["banner" ] = None
957
+ else :
958
+ bot_payload ["banner" ] = utils ._bytes_to_base64_data (banner )
959
+
960
+ if bio is not MISSING :
961
+ bot_payload ["bio" ] = bio or ""
962
+
963
+ if bot_payload and not me :
964
+ raise InvalidArgument (
965
+ "Can only edit avatar, banner, or bio for the bot's member."
966
+ )
967
+
913
968
if payload :
914
969
data = await http .edit_member (guild_id , self .id , reason = reason , ** payload )
915
- return Member (data = data , guild = self .guild , state = self ._state )
970
+ elif bot_payload :
971
+ data = await http .edit_member (guild_id , "@me" , reason = reason , ** bot_payload )
972
+ else :
973
+ return None
974
+
975
+ return Member (data = data , guild = self .guild , state = self ._state )
916
976
917
977
async def timeout (
918
978
self , until : datetime .datetime | None , * , reason : str | None = None
0 commit comments