如何在代码中更改 Discord 机器人头像 [python]
How to change discord bot avatar in code [python]
每天都给bot换昵称,但是怎么换头像,我找到了discord.py文档
avatar (bytes) - A bytes-like object representing the image to upload. Could be None to denote no avatar.
但是我连怎么用都不懂,是的,我知道,我是xD水壶
请帮忙
ClientUser.edit
的文档中对此进行了讨论:
Note
To upload an avatar, a 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
bytes-like object is given through the use of fp.read().
The only image formats supported for uploading is JPEG and PNG.
所以你会做类似的事情
with open(path_to_file, 'rb') as f:
image = f.read()
await bot.user.edit(avatar=image)
每天都给bot换昵称,但是怎么换头像,我找到了discord.py文档
avatar (bytes) - A bytes-like object representing the image to upload. Could be None to denote no avatar.
但是我连怎么用都不懂,是的,我知道,我是xD水壶
请帮忙
ClientUser.edit
的文档中对此进行了讨论:
Note
To upload an avatar, a 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 bytes-like object is given through the use of fp.read().
The only image formats supported for uploading is JPEG and PNG.
所以你会做类似的事情
with open(path_to_file, 'rb') as f:
image = f.read()
await bot.user.edit(avatar=image)