Utilisation
Initialiser
import Glyph from '@fca.gg/glyph';
Glyph.init();
init() lit list.json dans le dossier des emojis : lancez glyph build avant. L'appeler une seconde fois lève une erreur, et les méthodes qui lisent un emoji par son nom lèvent une erreur tant qu'il n'a pas été appelé (toIdentifier() et toCompact(), qui prennent un objet emoji, fonctionnent sans).
Méthodes
Glyph.get(name): l'emoji, sous la forme{id, name, animated}.Glyph.identifier(name): l'identifiant à écrire dans un message,<:name:id>ou<a:name:id>s'il est animé.Glyph.compact(name): l'identifiant avec le nom réduit à_, soit<:_:id>. Le rendu est le même sur Discord, avec un texte plus court : utile quand beaucoup d'emojis doivent tenir dans la limite de taille d'un message ou d'un composant.Glyph.id(name): l'identifiant numérique seul.Glyph.has(name):truesi l'emoji existe.Glyph.list(): tous les emojis.Glyph.size(): le nombre d'emojis.Glyph.toIdentifier(emoji)etGlyph.toCompact(emoji): les mêmes formats à partir d'un objet emoji.
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 disponibles`);
}
get() renvoie undefined pour un nom inconnu : vérifiez avec has() si le nom vient d'une saisie. Avec les types générés, TypeScript signale déjà les noms inconnus dans votre code.
Avec 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(`Bonjour ${Glyph.identifier('happy')}`);
});
client.login(process.env.TOKEN);