Auto-imports
What are auto-imports?
In a standard TypeScript project, you need to manually import every function or class you use:
import { command } from "@glyria/bot"
import { embedV2 } from "@glyria/bot"
import { GlyriaClient } from "@glyria/bot"
glyria.js eliminates this entirely. Every framework utility is automatically available as a global — no imports needed anywhere in your project.
// no imports — it just works
export default command()
.setName("ping")
.setDescription("Pong!")
.execute(async (ctx) => {
await ctx.reply({ content: "Pong!" })
})
How it works
glyria.js uses two mechanisms working together:
Runtime injection — when your bot starts, glyria.js injects all utilities into globalThis. Every file executed after that has access to them without importing.
Type declarations — glyria.js generates a .glyria/imports.d.ts file that tells TypeScript about the globals. This gives you full autocompletion and type checking in your IDE.
Available globals
Framework
| Global | Description |
|---|---|
GlyriaClient | The Discord bot client |
command | Slash command builder |
embedV2 | Embed V2 builder |
defineConfig | Config helper |
discord.js
| Global | Description |
|---|---|
GatewayIntentBits | Discord gateway intents |
User globals
Any function exported from src/utils/ or src/composables/ is also auto-imported.
// src/utils/useDatabase.ts
export const useDatabase = () => {
return {
find: (id: string) => { /* ... */ },
save: (data: any) => { /* ... */ },
}
}
// src/commands/ping.ts — no import needed
export default command()
.setName("ping")
.execute(async (ctx) => {
const db = useDatabase()
const user = await db.find(ctx.user.id)
})
Module globals
Modules declared in glyria.config.ts also expose their exports as globals, under a PascalCase namespace derived from the package name.
// glyria.config.ts
export default defineGlyriaConfig({
modules: ["@glyria/timers"]
})
// src/commands/remind.ts — no import needed
Timers.createJob(() => {
console.log("runs every minute")
}, "* * * * *")
| Package | Namespace |
|---|---|
@glyria/timers | Timers.* |
@glyria/economy | Economy.* |
@glyria/moderation | Moderation.* |
@glyria/timers → Timers, @glyria/some-feature → SomeFeature.Regenerating auto-imports
Auto-imports are regenerated automatically in dev mode. If you add a new utility in production, run:
npx glyria generate
tsconfig.json includes the .glyria/ folder:{
"include": ["src/**/*", ".glyria/**/*"]
}
.glyria/imports.d.ts file is auto-generated and will be overwritten on every glyria generate or glyria dev. Never edit it manually.
