diff --git a/src/structures/cdn.ts b/src/structures/cdn.ts index fc75238..e6e00c4 100644 --- a/src/structures/cdn.ts +++ b/src/structures/cdn.ts @@ -1,11 +1,13 @@ import { ImageFormats, ImageSize } from '../types/cdn.ts' +/** Function to get Image URL from a resource on Discord CDN */ export const ImageURL = ( url: string, - format: ImageFormats, - size?: ImageSize | 128 + format: ImageFormats | undefined = 'webp', + size: ImageSize | undefined = 128 ): string => { + size = size === undefined ? 128 : size if (url.includes('a_')) { - return `${url}.gif?size=${size}` - } else return `${url}.${format}?size=${size}` -} + return `${url}.${format === undefined ? 'gif' : format}?size=${size}` + } else return `${url}.${format === 'gif' ? 'webp' : format}?size=${size}` +} \ No newline at end of file diff --git a/src/structures/user.ts b/src/structures/user.ts index 1cd8843..10fbf6a 100644 --- a/src/structures/user.ts +++ b/src/structures/user.ts @@ -42,7 +42,7 @@ export class User extends Base { avatarURL(format: ImageFormats = 'webp', size: ImageSize = 512, dynamic: boolean = true): string { return this.avatar != null - ? `${ImageURL(USER_AVATAR(this.id, dynamic ? this.avatar : this.avatar.replace('a_', '')), format, size)}` + ? `${ImageURL(USER_AVATAR(this.id, this.avatar), format, size)}` : `${DEFAULT_USER_AVATAR(String(Number(this.discriminator) % 5))}.png` }