CIRCE / DOCUMENTATION
Environment
Validated environment variables and the credentials contract.
On this page
defineConfig(schema) validates process.env at startup. If anything is invalid, Circe lists every problem and exits with code 1.
Credentials contract
The validated result must contain token and clientId, and may contain guildId. The CLI uses them to log in and register commands. Environment variables are usually SCREAMING_CASE, so map them:
// src/config.ts
import { defineConfig } from "@sxnnyside/circe";
import { z } from "zod";
export default defineConfig(
z
.object({
DISCORD_TOKEN: z.string().min(1),
DISCORD_CLIENT_ID: z.string().min(1),
DISCORD_GUILD_ID: z.string().optional(),
DATABASE_URL: z.string().url().optional(),
})
.transform((env) => ({
token: env.DISCORD_TOKEN,
clientId: env.DISCORD_CLIENT_ID,
guildId: env.DISCORD_GUILD_ID,
databaseUrl: env.DATABASE_URL,
})),
);
Without the mapping,
tokenisundefinedand login fails withAn invalid token was provided.circe init1.2.0 templates use the raw names; add the transform. Since 1.2.1 the templates map them, and the CLI falls back toDISCORD_TOKEN,DISCORD_CLIENT_IDandDISCORD_GUILD_ID.
guildId
Set: commands register for that server and appear instantly. Unset: they register globally, slower to propagate. Use it in development, unset it in production.
Schema libraries
| Function | Accepts |
|---|---|
defineConfig |
A Zod schema. |
defineEnvConfig |
Any schema with safeParse: Valibot, ArkType, Standard Schema v1. |
Both return an object with .load(source?).
.env files
The CLI loads .env from the project folder. Variables already in the process environment win.
