Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
using Discord;
namespace Yonom.DiscordTools
{
static class DiscordAvatar
{
// for documentation purposes only
private static enum DefaultAvatars
{
blurple = 0,
grey = 1,
green = 2,
orange = 3,
red = 4,
total = 5
}
public static string GetAvatarUrlOrDefault(this IUser user)
{
return user.GetAvatarUrl() ?? GetDefaultAvatarUrl(user);
}
public static string GetDefaultAvatarUrl(this IUser user)
{
var imageId = user.DiscriminatorValue % (int)DefaultAvatars.total
return $"https://cdn.discordapp.com/embed/avatars/{imageID}.png";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment