Installation
Install the package
npm install @fca.gg/glyph
Prepare the project
npx glyph setup
This command:
- creates the
emojis/folder; - offers to generate a
glyph.config.jsfile with the default configuration; - adds
emojis/list.jsonto.gitignore; - adds
emojis/emojis.d.tsto theincludeof yourtsconfig.json.
Configure
Glyph reads its configuration from glyph.config.js at the root of the project:
import dotenv from 'dotenv';
dotenv.config();
const config = {
emojisDir: './emojis', // folder of images
fileIndex: true, // generates list.json and emojis.d.ts
botToken: process.env.TOKEN, // Discord bot token
apiBaseUrl: process.env.DISCORD_API, // API root (unset: Discord)
};
export default config;
emojisDir(default:'./emojis'): folder of emoji images.fileIndex(default:true): generates thelist.jsonandemojis.d.tsindex files.botToken: the bot token. Without a token,glyph buildcan only update the types.apiBaseUrl(default:https://discord.com/api/v10): root of the Discord API.
An option left undefined (or empty) keeps its default instead of erasing it: a missing environment variable means Discord, not a broken URL.
Without a configuration file
Without glyph.config.js, Glyph reads these environment variables:
TOKEN: the bot token;EMOJIS_DIR: the emojis folder;DISCORD_API: the API root.
As soon as glyph.config.js exists, these variables are no longer read automatically. The file is JavaScript, so it can read them itself, as in the example above.
Keep the token out of the repository, for example in a .env file:
TOKEN=your_bot_token
Going through a proxy or a simulator
apiBaseUrl decides where emojis are pushed. Two reasons to change it:
- a REST proxy, when the whole application goes through one to share rate limits or observe traffic: Glyph should take the same path instead of going around it;
- a Discord simulator during tests, so you don't touch the application's real emojis, which every server the bot is on can see.
DISCORD_API=http://localhost:7070/api/v10 npx glyph build
When the root is not Discord, glyph build prints it: one visible line prevents pushing to a proxy without realizing it. A trailing slash is removed automatically.