Auto-imports
What are auto-imports?
In a standard TypeScript project, you need to manually import every function or class you use:
import { GlyriaCommand } from "@glyria/bot"
import { EmbedV2Builder } 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 new GlyriaCommand()
.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 |
GlyriaCommand | Slash command builder |
GlyriaUserCommand | User context-menu command builder |
GlyriaMessageCommand | Message context-menu command builder |
GlyriaEvent | Event listener builder |
EmbedV2Builder | Embed V2 builder |
GlyriaBus | Event bus |
globalBus | Shared framework event bus singleton |
createReplyableContext | Replyable context helper |
useCommands | Command registry accessor |
defineGlyriaConfig | Config helper |
logger | Styled terminal logger |
hexToNumber | Hex color to number utility |
Events | discord.js Events enum |
discord.js
The entire discord.js library is available under the djs namespace — no imports needed:
djs.PermissionsBitField.Flags.BanMembers
djs.GatewayIntentBits.Guilds
djs.ButtonStyle.Primary
// ... everything discord.js exports
User globals
Any function exported from src/utils/, src/composables/, or src/index.ts is also auto-imported globally.
// src/utils/useDatabase.ts
export const useDatabase = () => {
return {
find: (id: string) => { /* ... */ },
save: (data: any) => { /* ... */ },
}
}
// src/commands/ping.ts — no import needed
export default new GlyriaCommand()
.setName("ping")
.execute(async (ctx) => {
const db = useDatabase()
const user = await db.find(ctx.user.id)
})
Custom folders
By default, src/utils/ and src/composables/ are scanned. You can add your own folders in glyria.config.ts:
export default defineGlyriaConfig({
dev: {
autoImportDirs: ['utils', 'composables', 'helpers', 'lib']
}
})
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.
