-
-
Save Rapptz/114738e29f403612e83260f31f13004b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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