bashdiscord

Is there a way to simply get a Discord server's icon using Bash?


Is it possible to get a Discord server's icon using the server's invite link or server ID using a bash script? I searched the docs here but couldn't find what I'm looking for.

My goal is to create a bash script and when I run it like this it'll download that server's icon using curl or wget;

./myScript <discord invite link/server ID>

Example server invite: https://discord.com/invite/wow

Same server's ID: 113103747126747136

Thanks!


Solution

  • Use the invite API.

    url=https://discord.com/invite/wow
    invite=$(basename "$url")
    invitejson=$(curl "https://discord.com/api/invites/$invite")
    servericon=$(<<<"$invitejson" jq -r '.guild.icon')
    serverid=$(<<<"$invitejson" jq -r '.guild.id')
    case "$servericon" in
       a_*) ext="gif" ;;
       *) ext="png" # ??
    esac
    wget "https://cdn.discordapp.com/icons/$serverid/$servericon.$ext"
    xdg-open "$servericon.gif"