mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
* tojson things * fix client * ignore private properties * remove extra property descriptors * handle primitive flattening * remove unused import * add toJSON to collections * reduce stateful props * state * allow custom prop names when flattening * fix client * fix build * fix flatten docs * remove guild.available, cleanup permissions, remove arbitrary id reduction * fix util import * add valueOf as needed, update member props * fix incorrect merge * update permissionoverwrites and permissions remove serialization of permissions in PermissionOverwrites#toJSON. change Permissions#toJSON to serialize permissions, by default excluding admin checks. * change Permissions#toJSON to return the primitive * Permissions#toJSON explicitly return bitfield
76 lines
1.7 KiB
JavaScript
76 lines
1.7 KiB
JavaScript
const Base = require('./Base');
|
|
|
|
/**
|
|
* Represents an emoji, see {@link GuildEmoji} and {@link ReactionEmoji}.
|
|
* @extends {Base}
|
|
*/
|
|
class Emoji extends Base {
|
|
constructor(client, emoji) {
|
|
super(client);
|
|
/**
|
|
* Whether this emoji is animated
|
|
* @type {boolean}
|
|
*/
|
|
this.animated = emoji.animated;
|
|
|
|
/**
|
|
* The name of this emoji
|
|
* @type {string}
|
|
*/
|
|
this.name = emoji.name;
|
|
|
|
/**
|
|
* The ID of this emoji
|
|
* @type {?Snowflake}
|
|
*/
|
|
this.id = emoji.id;
|
|
}
|
|
|
|
/**
|
|
* The identifier of this emoji, used for message reactions
|
|
* @type {string}
|
|
* @readonly
|
|
*/
|
|
get identifier() {
|
|
if (this.id) return `${this.animated ? 'a:' : ''}${this.name}:${this.id}`;
|
|
return encodeURIComponent(this.name);
|
|
}
|
|
|
|
/**
|
|
* The URL to the emoji file if its a custom emoji
|
|
* @type {?string}
|
|
* @readonly
|
|
*/
|
|
get url() {
|
|
if (!this.id) return null;
|
|
return this.client.rest.cdn.Emoji(this.id, this.animated ? 'gif' : 'png');
|
|
}
|
|
|
|
/**
|
|
* When concatenated with a string, this automatically returns the text required to form a graphical emoji on Discord
|
|
* instead of the Emoji object.
|
|
* @returns {string}
|
|
* @example
|
|
* // Send a custom emoji from a guild:
|
|
* const emoji = guild.emojis.first();
|
|
* msg.reply(`Hello! ${emoji}`);
|
|
* @example
|
|
* // Send the emoji used in a reaction to the channel the reaction is part of
|
|
* reaction.message.channel.send(`The emoji used was: ${reaction.emoji}`);
|
|
*/
|
|
toString() {
|
|
return this.id ? `<${this.animated ? 'a' : ''}:${this.name}:${this.id}>` : this.name;
|
|
}
|
|
|
|
toJSON() {
|
|
return super.toJSON({
|
|
guild: 'guildID',
|
|
createdTimestamp: true,
|
|
url: true,
|
|
identifier: true,
|
|
});
|
|
}
|
|
}
|
|
|
|
module.exports = Emoji;
|