'Merging two discord banner commands into one

hi im trying to turn my two banner gifs into just one, right now i have one for gifs and just basic images. How would i be able to make them show a gif and if its not a gif just show the image or the color thats set?

@client.command(aliases=['bn'])
async def banner(ctx, member: discord.Member=None):
    if member == None:
        member = ctx.author

    icon_url = member.avatar_url

    avatarEmbed = discord.Embed(title = f"{member.name}\'s Banner", color = 0x8bc1a9)
    req = await client.http.request(discord.http.Route("GET", "/users/{uid}", uid=member.id))
    banner_id = req["banner"]
    
    if banner_id:
        banner_url = f"https://cdn.discordapp.com/banners/{member.id}/{banner_id}?size=1024"
    avatarEmbed.set_image(url = f"{banner_url}")

    avatarEmbed.timestamp = ctx.message.created_at

    await ctx.send(embed = avatarEmbed)


@client.command(aliases=['bngif'])
async def bannergif(ctx, member: discord.Member=None):
    if member == None:
        member = ctx.author

    icon_url = member.avatar_url

    avatarEmbed = discord.Embed(title = f"{member.name}\'s Banner", color = 0x8bc1a9)
    req = await client.http.request(discord.http.Route("GET", "/users/{uid}", uid=member.id))
    banner_id = req["banner"]
    
    if banner_id:
        banner_url = f"https://cdn.discordapp.com/banners/{member.id}/{banner_id}.gif?size=1024"
    avatarEmbed.set_image(url = f"{banner_url}")

    avatarEmbed.timestamp = ctx.message.created_at

    await ctx.send(embed = avatarEmbed)


Solution 1:[1]

Gif banners' hashes (ids) start with a_ so you can change the file extension depending on that.

image_size = '?size=1024'
animated = banner_hash.startswith('a_')
file_extension = 'gif' if animated else 'png'
image_base_url = 'https://cdn.discordapp.com/'
banners_endpoint = f'banners/{member.id}/{banner_hash}.{file_extension}'
image = f'{image_base_url}{banners_endpoint}{image_size}'

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 3nws