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
@@ -782,6 +783,9 @@ async def edit(
782
783
reason : str | None = None ,
783
784
communication_disabled_until : datetime .datetime | None = MISSING ,
784
785
bypass_verification : bool | None = MISSING ,
786
+ banner : bytes | None = MISSING ,
787
+ avatar : bytes | None = MISSING ,
788
+ bio : str | None = MISSING ,
785
789
) -> Member | None :
786
790
"""|coro|
787
791
@@ -817,6 +821,14 @@ async def edit(
817
821
818
822
- Client has ALL THREE of :attr:`Permissions.moderate_members`, :attr:`Permissions.kick_members`, and :attr:`Permissions.ban_members`
819
823
824
+ .. note::
825
+
826
+ The following parameters are only available when editing the bot's own member:
827
+
828
+ - ``avatar``
829
+ - ``banner``
830
+ - ``bio``
831
+
820
832
All parameters are optional.
821
833
822
834
.. versionchanged:: 1.1
@@ -854,6 +866,26 @@ async def edit(
854
866
Indicates if the member should bypass the guild's verification requirements.
855
867
856
868
.. versionadded:: 2.6
869
+ banner: Optional[:class:`bytes`]
870
+ A :term:`py:bytes-like object` representing the banner.
871
+ Could be ``None`` to denote removal of the banner.
872
+
873
+ This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
874
+
875
+ .. versionadded:: 2.7
876
+ avatar: Optional[:class:`bytes`]
877
+ A :term:`py:bytes-like object` representing the avatar.
878
+ Could be ``None`` to denote removal of the avatar.
879
+
880
+ This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
881
+
882
+ .. versionadded:: 2.7
883
+ bio: Optional[:class:`str`]
884
+ The new bio for the member. Could be ``None`` to denote removal of the bio.
885
+
886
+ This is only available when editing the bot's own member (i.e. :attr:`Guild.me`).
887
+
888
+ .. versionadded:: 2.7
857
889
858
890
Returns
859
891
-------
@@ -867,16 +899,19 @@ async def edit(
867
899
You do not have the proper permissions to the action requested.
868
900
HTTPException
869
901
The operation failed.
902
+ InvalidArgument
903
+ You tried to edit the avatar, banner, or bio of a member that is not the bot.
870
904
"""
871
905
http = self ._state .http
872
906
guild_id = self .guild .id
873
907
me = self ._state .self_id == self .id
874
908
payload : dict [str , Any ] = {}
909
+ bot_payload : dict [str , Any ] = {}
875
910
876
911
if nick is not MISSING :
877
912
nick = nick or ""
878
913
if me :
879
- await http . change_my_nickname ( guild_id , nick , reason = reason )
914
+ bot_payload [ " nick" ] = nick
880
915
else :
881
916
payload ["nick" ] = nick
882
917
@@ -923,9 +958,34 @@ async def edit(
923
958
flags .bypasses_verification = bypass_verification
924
959
payload ["flags" ] = flags .value
925
960
961
+ if avatar is not MISSING :
962
+ if avatar is None :
963
+ bot_payload ["avatar" ] = None
964
+ else :
965
+ bot_payload ["avatar" ] = utils ._bytes_to_base64_data (avatar )
966
+
967
+ if banner is not MISSING :
968
+ if banner is None :
969
+ bot_payload ["banner" ] = None
970
+ else :
971
+ bot_payload ["banner" ] = utils ._bytes_to_base64_data (banner )
972
+
973
+ if bio is not MISSING :
974
+ bot_payload ["bio" ] = bio or ""
975
+
976
+ if bot_payload and not me :
977
+ raise InvalidArgument (
978
+ "Can only edit avatar, banner, or bio for the bot's member."
979
+ )
980
+
926
981
if payload :
927
982
data = await http .edit_member (guild_id , self .id , reason = reason , ** payload )
928
- return Member (data = data , guild = self .guild , state = self ._state )
983
+ elif bot_payload :
984
+ data = await http .edit_member (guild_id , "@me" , reason = reason , ** bot_payload )
985
+ else :
986
+ return None
987
+
988
+ return Member (data = data , guild = self .guild , state = self ._state )
929
989
930
990
async def timeout (
931
991
self , until : datetime .datetime | None , * , reason : str | None = None
0 commit comments