Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Emoji): Add imageURL() #9788

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions packages/discord.js/src/structures/BaseGuildEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,23 @@ class BaseGuildEmoji extends Emoji {
}
}

/**
* Returns a URL for the emoji.
* @method imageURL
* @memberof BaseGuildEmoji
* @instance
* @param {BaseImageURLOptions} [options] Options for the image URL
* @returns {string}
*/

/**
* Returns a URL for the emoji.
* @name url
* @memberof BaseGuildEmoji
* @instance
* @type {string}
* @readonly
* @deprecated Use {@link BaseGuildEmoji#imageURL} instead.
*/

module.exports = BaseGuildEmoji;
22 changes: 20 additions & 2 deletions packages/discord.js/src/structures/Emoji.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
'use strict';

const process = require('node:process');
const { DiscordSnowflake } = require('@sapphire/snowflake');
const Base = require('./Base');

let deprecationEmittedForURL = false;

/**
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
* @extends {Base}
Expand Down Expand Up @@ -40,12 +43,27 @@ class Emoji extends Base {
}

/**
* The URL to the emoji file if it's a custom emoji
* Returns a URL for the emoji or `null` if this is not a custom emoji.
* @param {BaseImageURLOptions} [options] Options for the image URL
* @returns {?string}
*/
imageURL(options) {
return this.id && this.client.rest.cdn.emoji(this.id, options);
}

/**
* Returns a URL for the emoji or `null` if this is not a custom emoji.
* @type {?string}
* @readonly
* @deprecated Use {@link Emoji#imageURL} instead.
*/
get url() {
return this.id && this.client.rest.cdn.emoji(this.id, this.animated ? 'gif' : 'png');
if (!deprecationEmittedForURL) {
process.emitWarning('The Emoji#url getter is deprecated. Use Emoji#imageURL() instead.', 'DeprecationWarning');
deprecationEmittedForURL = true;
}

return this.imageURL({ extension: this.animated ? 'gif' : 'png' });
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,8 @@ export abstract class BaseGuild extends Base {

export class BaseGuildEmoji extends Emoji {
protected constructor(client: Client<true>, data: RawGuildEmojiData, guild: Guild | GuildPreview);
public imageURL(options?: BaseImageURLOptions): string;
public get url(): string;
public available: boolean | null;
public get createdAt(): Date;
public get createdTimestamp(): number;
Expand Down Expand Up @@ -1312,6 +1314,7 @@ export class Emoji extends Base {
public id: Snowflake | null;
public name: string | null;
public get identifier(): string;
public imageURL(options?: BaseImageURLOptions): string | null;
public get url(): string | null;
public toJSON(): unknown;
public toString(): string;
Expand Down Expand Up @@ -1530,7 +1533,6 @@ export class GuildEmoji extends BaseGuildEmoji {
public guild: Guild;
public author: User | null;
public get roles(): GuildEmojiRoleManager;
public get url(): string;
public delete(reason?: string): Promise<GuildEmoji>;
public edit(options: GuildEmojiEditOptions): Promise<GuildEmoji>;
public equals(other: GuildEmoji | unknown): boolean;
Expand Down