Usage
Initialize
import Glyph from '@fca.gg/glyph';
Glyph.init();
init() reads list.json from the emojis folder: run glyph build first. Calling it a second time throws an error, and the methods that read an emoji by name throw until it has been called (toIdentifier() and toCompact(), which take an emoji object, work without it).
Methods
Glyph.get(name): the emoji, as{id, name, animated}.Glyph.identifier(name): the identifier to write in a message,<:name:id>, or<a:name:id>when animated.Glyph.compact(name): the identifier with the name reduced to_, that is<:_:id>. It renders the same on Discord with shorter text: useful when many emojis must fit within the size limit of a message or a component.Glyph.id(name): the numeric ID alone.Glyph.has(name):truewhen the emoji exists.Glyph.list(): every emoji.Glyph.size(): the number of emojis.Glyph.toIdentifier(emoji)andGlyph.toCompact(emoji): the same formats from an emoji object.
Glyph.get('happy');
// { id: "794367836033515531", name: "happy", animated: false }
Glyph.identifier('happy'); // "<:happy:794367836033515531>"
Glyph.compact('happy'); // "<:_:794367836033515531>"
if (Glyph.has('party')) {
console.log(`${Glyph.size()} emojis available`);
}
get() returns undefined for an unknown name: check with has() when the name comes from user input. With the generated types, TypeScript already flags unknown names in your code.
With discord.js
import {Client, GatewayIntentBits} from 'discord.js';
import Glyph from '@fca.gg/glyph';
Glyph.init();
const client = new Client({intents: [GatewayIntentBits.Guilds]});
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand() || interaction.commandName !== 'hello') return;
await interaction.reply(`Hello ${Glyph.identifier('happy')}`);
});
client.login(process.env.TOKEN);