discord.py

Discord.py How to download the server icon?


I want to make my bot download the server icon, but using that guild.icon I only get a string of numbers and letters and not a URL. Can someone help?


Solution

  • In the documentation you can see that you can use guild.icon_url to get an url to the servers icon. So if you want to get the server icon from the guild a message is from.

    You can use ctx.guild.icon_url to get the url to the icon:

    @commands.command()
    async def get_server_icon_url(self, ctx):
        icon_url = ctx.guild.icon_url
        await ctx.send(f"The icon url is: {icon_url}")
    

    The reason that guild.icon does not work as expected. Is that guild.icon returns the hash of the icon instead of an url.