feat!: Support animated WebP (#10911)

* feat: support animated WebP

* refactor: change the rest

* fix: remove redundant code
This commit is contained in:
Jiralite
2025-05-27 10:18:30 +01:00
committed by GitHub
parent 78d512c347
commit 2c35084ecd
6 changed files with 67 additions and 38 deletions

View File

@@ -779,6 +779,11 @@ exports.Client = Client;
* @see {@link https://discord.js.org/docs/packages/rest/stable/ImageURLOptions:Interface}
*/
/**
* @external EmojiURLOptions
* @see {@link https://discord.js.org/docs/packages/rest/stable/EmojiURLOptions:TypeAlias}
*/
/**
* @external BaseImageURLOptions
* @see {@link https://discord.js.org/docs/packages/rest/stable/BaseImageURLOptions:Interface}

View File

@@ -58,7 +58,7 @@ class BaseGuildEmoji extends Emoji {
* @method imageURL
* @memberof BaseGuildEmoji
* @instance
* @param {ImageURLOptions} [options={}] Options for the image URL
* @param {EmojiURLOptions} [options={}] Options for the emoji URL
* @returns {string}
*/

View File

@@ -42,11 +42,20 @@ class Emoji extends Base {
/**
* Returns a URL for the emoji or `null` if this is not a custom emoji.
* @param {ImageURLOptions} [options={}] Options for the image URL
* @param {EmojiURLOptions} [options={}] Options for the emoji URL
* @returns {?string}
*/
imageURL(options = {}) {
return this.id && this.client.rest.cdn.emoji(this.id, this.animated, options);
if (!this.id) return null;
// Return a dynamic extension depending on whether the emoji is animated.
const resolvedOptions = { extension: options.extension, size: options.size };
if (!options.extension || options.extension === 'webp') {
resolvedOptions.animated = options.animated ?? (this.animated || undefined);
}
return this.client.rest.cdn.emoji(this.id, resolvedOptions);
}
/**

View File

@@ -1,6 +1,6 @@
import { ApplicationCommandOptionAllowedChannelTypes, MessageActionRowComponentBuilder } from '@discordjs/builders';
import { Collection, ReadonlyCollection } from '@discordjs/collection';
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions } from '@discordjs/rest';
import { BaseImageURLOptions, ImageURLOptions, RawFile, REST, RESTOptions, EmojiURLOptions } from '@discordjs/rest';
import { Awaitable, JSONEncodable } from '@discordjs/util';
import { WebSocketManager, WebSocketManagerOptions } from '@discordjs/ws';
import { AsyncEventEmitter } from '@vladfrangu/async_event_emitter';
@@ -590,7 +590,7 @@ export abstract class BaseGuild extends Base {
export class BaseGuildEmoji extends Emoji {
protected constructor(client: Client<true>, data: APIEmoji, guild: Guild | GuildPreview);
public imageURL(options?: ImageURLOptions): string;
public imageURL(options?: EmojiURLOptions): string;
public get url(): string;
public available: boolean | null;
public get createdAt(): Date;
@@ -1267,7 +1267,7 @@ export class Emoji extends Base {
public id: Snowflake | null;
public name: string | null;
public get identifier(): string;
public imageURL(options?: ImageURLOptions): string | null;
public imageURL(options?: EmojiURLOptions): string | null;
public get url(): string | null;
public toJSON(): unknown;
public toString(): string;