code: public static Icon getAvatar(DiscordApi api, String avatarHash, String discriminator, long userId) {
          StringBuilder url = new StringBuilder("https://cdn.discordapp.com/");
          if (avatarHash == null) {
              url.append("embed/avatars/")
                      .append(Integer.parseInt(discriminator) % 5)
                      .append(".png");
          } else {
              url.append("avatars/")
                      .append(userId).append('/').append(avatarHash)
                      .append(avatarHash.startsWith("a_") ? ".gif" : ".png");
          }
          try {
              return new IconImpl(api, new URL(url.toString()));
          } catch (MalformedURLException e) {
              logger.warn("Seems like the url of the avatar is malformed! Please contact the developer!", e);
              return null;
          }
      }
docs: Gets the avatar for the given details.
  
  @param api The discord api instance.
  @param avatarHash The avatar hash or {@code null} for default avatar.
  @param discriminator The discriminator if default avatar is wanted.
  @param userId The user id.
  @return The avatar for the given details.