Add links to reply embeds and fix nitro custom server avatars not displaying
This commit is contained in:
@@ -8,15 +8,21 @@ use twilight_model::util::ImageHash;
|
||||
/// * `hash` - The user's avatar hash (if available).
|
||||
/// * `user_id` - The user's ID.
|
||||
/// * `discriminator` - The user's discriminator.
|
||||
/// * `guild_id` - The guild ID, **only set if the user has Nitro and a custom avatar for the
|
||||
/// server. Otherwise, even in a server, this is NOT SET**.
|
||||
///
|
||||
/// Returns:
|
||||
/// [`String`] - The URL of the user's avatar.
|
||||
pub fn get_avatar_url(hash: Option<ImageHash>, user_id: u64, discriminator: u64) -> String {
|
||||
pub fn get_avatar_url(hash: Option<ImageHash>, user_id: u64, discriminator: u64, guild_id: Option<u64>) -> String {
|
||||
if let Some(hash) = hash {
|
||||
format!("https://cdn.discordapp.com/avatars/{user_id}/{hash}.png?size=256")
|
||||
if let Some(guild_id) = guild_id {
|
||||
return format!("https://cdn.discordapp.com/guilds/{guild_id}/users/{user_id}/avatars/{hash}.webp?size=256");
|
||||
}
|
||||
|
||||
format!("https://cdn.discordapp.com/avatars/{user_id}/{hash}.webp?size=256")
|
||||
} else {
|
||||
format!(
|
||||
"https://cdn.discordapp.com/embed/avatars/{}.png?size=256",
|
||||
"https://cdn.discordapp.com/embed/avatars/{}.webp?size=256",
|
||||
match discriminator.to_string().as_str() {
|
||||
"0" => (user_id >> 22) % 6,
|
||||
_ => discriminator % 6,
|
||||
|
||||
Reference in New Issue
Block a user