diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 987fa38f2..6b22cd25b 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -433,9 +433,9 @@ class Guild extends Base { * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ - iconURL({ format, size } = {}) { + iconURL({ format, size, dynamic } = {}) { if (!this.icon) return null; - return this.client.rest.cdn.Icon(this.id, this.icon, format, size); + return this.client.rest.cdn.Icon(this.id, this.icon, format, size, dynamic); } /** diff --git a/src/structures/User.js b/src/structures/User.js index a4b1d3d92..7ae67451b 100644 --- a/src/structures/User.js +++ b/src/structures/User.js @@ -140,9 +140,9 @@ class User extends Base { * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ - avatarURL({ format, size } = {}) { + avatarURL({ format, size, dynamic } = {}) { if (!this.avatar) return null; - return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size); + return this.client.rest.cdn.Avatar(this.id, this.avatar, format, size, dynamic); } /** diff --git a/src/util/Constants.js b/src/util/Constants.js index 6ef681272..a2e86d4ae 100644 --- a/src/util/Constants.js +++ b/src/util/Constants.js @@ -119,7 +119,9 @@ function makeImageUrl(root, { format = 'webp', size } = {}) { * Options for Image URLs. * @typedef {Object} ImageURLOptions * @property {string} [format] One of `webp`, `png`, `jpg`, `gif`. If no format is provided, - * it will be `gif` for animated avatars or otherwise `webp` + * defaults to `webp`. + * @property {boolean} [dynamic] If true, the format will dynamically change to `gif` for + * animated avatars; the default is false. * @property {number} [size] One of `16`, `32`, `64`, `128`, `256`, `512`, `1024`, `2048` */ @@ -129,14 +131,14 @@ exports.Endpoints = { Emoji: (emojiID, format = 'png') => `${root}/emojis/${emojiID}.${format}`, Asset: name => `${root}/assets/${name}`, DefaultAvatar: discriminator => `${root}/embed/avatars/${discriminator}.png`, - Avatar: (userID, hash, format = 'default', size) => { - if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp'; + Avatar: (userID, hash, format = 'webp', size, dynamic = false) => { + if (dynamic) format = hash.startsWith('a_') ? 'gif' : format; return makeImageUrl(`${root}/avatars/${userID}/${hash}`, { format, size }); }, Banner: (guildID, hash, format = 'webp', size) => makeImageUrl(`${root}/banners/${guildID}/${hash}`, { format, size }), - Icon: (guildID, hash, format = 'default', size) => { - if (format === 'default') format = hash.startsWith('a_') ? 'gif' : 'webp'; + Icon: (guildID, hash, format = 'webp', size, dynamic = false) => { + if (dynamic) format = hash.startsWith('a_') ? 'gif' : format; return makeImageUrl(`${root}/icons/${guildID}/${hash}`, { format, size }); }, AppIcon: (clientID, hash, { format = 'webp', size } = {}) => diff --git a/typings/index.d.ts b/typings/index.d.ts index 832bfae42..c5eb84f91 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -272,9 +272,9 @@ declare module 'discord.js' { public name: string; public owner: User | Team | null; public rpcOrigins: string[]; - public coverImage(options?: AvatarOptions): string; + public coverImage(options?: ImageURLOptions): string; public fetchAssets(): Promise; - public iconURL(options?: AvatarOptions): string; + public iconURL(options?: ImageURLOptions): string; public toJSON(): object; public toString(): string; } @@ -291,7 +291,7 @@ declare module 'discord.js' { public readonly createdAt: Date; public readonly createdTimestamp: number; - public iconURL(options?: AvatarOptions): string; + public iconURL(options?: ImageURLOptions): string; public toJSON(): object; public toString(): string; } @@ -726,7 +726,7 @@ declare module 'discord.js' { public widgetChannelID: Snowflake | null; public widgetEnabled: boolean | null; public addMember(user: UserResolvable, options: AddGuildMemberOptions): Promise; - public bannerURL(options?: AvatarOptions): string | null; + public bannerURL(options?: ImageURLOptions): string | null; public createIntegration(data: IntegrationData, reason?: string): Promise; public delete(): Promise; public edit(data: GuildEditData, reason?: string): Promise; @@ -740,7 +740,7 @@ declare module 'discord.js' { public fetchVanityCode(): Promise; public fetchVoiceRegions(): Promise>; public fetchWebhooks(): Promise>; - public iconURL(options?: AvatarOptions): string | null; + public iconURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null; public leave(): Promise; public member(user: UserResolvable): GuildMember | null; public setAFKChannel(afkChannel: ChannelResolvable | null, reason?: string): Promise; @@ -759,7 +759,7 @@ declare module 'discord.js' { public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise; public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise; public setVerificationLevel(verificationLevel: number, reason?: string): Promise; - public splashURL(options?: AvatarOptions): string | null; + public splashURL(options?: ImageURLOptions): string | null; public toJSON(): object; public toString(): string; } @@ -1189,8 +1189,8 @@ declare module 'discord.js' { public largeText: string | null; public smallImage: Snowflake | null; public smallText: string | null; - public largeImageURL(options: AvatarOptions): string | null; - public smallImageURL(options: AvatarOptions): string | null; + public largeImageURL(options: ImageURLOptions): string | null; + public smallImageURL(options: ImageURLOptions): string | null; } export class Role extends Base { @@ -1421,10 +1421,10 @@ declare module 'discord.js' { public system?: boolean; public readonly tag: string; public username: string; - public avatarURL(options?: AvatarOptions): string | null; + public avatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string | null; public createDM(): Promise; public deleteDM(): Promise; - public displayAvatarURL(options?: AvatarOptions): string; + public displayAvatarURL(options?: ImageURLOptions & { dynamic?: boolean }): string; public equals(user: User): boolean; public fetch(): Promise; public toString(): string; @@ -2011,7 +2011,7 @@ declare module 'discord.js' { new?: any; } - interface AvatarOptions { + interface ImageURLOptions { format?: ImageExt; size?: ImageSize; }