Skip to content
Advertisement

(discord.py) change discord avatar with someone’s avatar url

I’m trying to change my bot’s avatar with the avatar url of someone in my server. The code isn’t working. Any help?

@bot.event
async def on_ready():
        avatar_url="https://cdn.discordapp.com/avatars/834942728953135115/315376d20a50a86450e9e3b91ff66123.webp?size=1024" #avatar url of someone in my server
        await bot.user.edit(avatar=avatar_url)

Advertisement

Answer

The other answer says you have to have a bytes-like object, which is true. Adding onto it though: you can retrieve the image as a bytes-like object with requests like: img = requests.get(url).content which you can then use in the await bot.user.edit(avatar=img) (replace url with your url or make a variable called url that contains the url) (and ofc import requests at the start of your script)

as someone has pointed out requests is sequential and thus blocking the async loop, which you dont really want (though for just updating it once it wont hurt too much :D). So if you want to do it properly, you should look at the docs for aiohttp

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement