Skip to content

Commit b6c762c

Browse files
authored
feat(Emoji): Add imageURL() (#9788)
feat(Emoji): add `imageURL()`
1 parent 85a78f9 commit b6c762c

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/discord.js/src/structures/BaseGuildEmoji.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,23 @@ class BaseGuildEmoji extends Emoji {
5353
}
5454
}
5555

56+
/**
57+
* Returns a URL for the emoji.
58+
* @method imageURL
59+
* @memberof BaseGuildEmoji
60+
* @instance
61+
* @param {BaseImageURLOptions} [options] Options for the image URL
62+
* @returns {string}
63+
*/
64+
65+
/**
66+
* Returns a URL for the emoji.
67+
* @name url
68+
* @memberof BaseGuildEmoji
69+
* @instance
70+
* @type {string}
71+
* @readonly
72+
* @deprecated Use {@link BaseGuildEmoji#imageURL} instead.
73+
*/
74+
5675
module.exports = BaseGuildEmoji;

packages/discord.js/src/structures/Emoji.js

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
'use strict';
22

3+
const process = require('node:process');
34
const { DiscordSnowflake } = require('@sapphire/snowflake');
45
const Base = require('./Base');
56

7+
let deprecationEmittedForURL = false;
8+
69
/**
710
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
811
* @extends {Base}
@@ -40,12 +43,27 @@ class Emoji extends Base {
4043
}
4144

4245
/**
43-
* The URL to the emoji file if it's a custom emoji
46+
* Returns a URL for the emoji or `null` if this is not a custom emoji.
47+
* @param {BaseImageURLOptions} [options] Options for the image URL
48+
* @returns {?string}
49+
*/
50+
imageURL(options) {
51+
return this.id && this.client.rest.cdn.emoji(this.id, options);
52+
}
53+
54+
/**
55+
* Returns a URL for the emoji or `null` if this is not a custom emoji.
4456
* @type {?string}
4557
* @readonly
58+
* @deprecated Use {@link Emoji#imageURL} instead.
4659
*/
4760
get url() {
48-
return this.id && this.client.rest.cdn.emoji(this.id, this.animated ? 'gif' : 'png');
61+
if (!deprecationEmittedForURL) {
62+
process.emitWarning('The Emoji#url getter is deprecated. Use Emoji#imageURL() instead.', 'DeprecationWarning');
63+
deprecationEmittedForURL = true;
64+
}
65+
66+
return this.imageURL({ extension: this.animated ? 'gif' : 'png' });
4967
}
5068

5169
/**

packages/discord.js/typings/index.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,6 +627,8 @@ export abstract class BaseGuild extends Base {
627627

628628
export class BaseGuildEmoji extends Emoji {
629629
protected constructor(client: Client<true>, data: RawGuildEmojiData, guild: Guild | GuildPreview);
630+
public imageURL(options?: BaseImageURLOptions): string;
631+
public get url(): string;
630632
public available: boolean | null;
631633
public get createdAt(): Date;
632634
public get createdTimestamp(): number;
@@ -1312,6 +1314,7 @@ export class Emoji extends Base {
13121314
public id: Snowflake | null;
13131315
public name: string | null;
13141316
public get identifier(): string;
1317+
public imageURL(options?: BaseImageURLOptions): string | null;
13151318
public get url(): string | null;
13161319
public toJSON(): unknown;
13171320
public toString(): string;
@@ -1530,7 +1533,6 @@ export class GuildEmoji extends BaseGuildEmoji {
15301533
public guild: Guild;
15311534
public author: User | null;
15321535
public get roles(): GuildEmojiRoleManager;
1533-
public get url(): string;
15341536
public delete(reason?: string): Promise<GuildEmoji>;
15351537
public edit(options: GuildEmojiEditOptions): Promise<GuildEmoji>;
15361538
public equals(other: GuildEmoji | unknown): boolean;

0 commit comments

Comments
 (0)