Typing a plugin
Type the plugins you attached on this.core with seedcord codegen. Covers what the generated Core block holds and when to run codegen again.
You attached the plugin, but this.core.db still fails to compile. The property is there when the bot runs, so only the types are missing. attach returns a bot typed with db, but a handler reads this.core. seedcord declares the type of this.core in its own package, which never imports your bot file.
A declare module block written by hand for every key works too, though you'd have to update it each time you rename one. seedcord codegen writes that block for you into src/seedcord-gen.d.ts.
@SlashRoute('history')
export class History extends SlashHandler<'history'> {
public async execute(): Promise<void> {
await this.reply(String(this.core.db)); }
}TypeScript reports "Property 'db' does not exist on type 'Core'" on this.core.db. Nothing is wrong with the handler itself.
What codegen writes
Every key you attached becomes one row on Core, sorted by key. The same file also holds your command and emoji registries, which this sample leaves out.
// Generated by `seedcord codegen`. Do not edit by hand.
// Run `seedcord codegen` after changing your commands, plugins, or emoji config.
import type Bot from './bot';
// prettier-ignore
declare module '@seedcord/gateway' {
interface Core {
db: (typeof Bot)['db'];
}
// SlashRegistry, the context menu registries, and EmojiMap follow
}
export {};Bot is the default export of the file your instance config key points at. Each row reads its type straight from that bot, so db gets exactly the type attach produced, Mongoose here. If you export the bot only as a named const, codegen stops with the code CliInstanceInvalid before it writes anything.
The Core block only appears once you've attached something.
Gateway and http differ
Each transport package declares its own Core, so the declare module line uses the package you import Seedcord from. A gateway bot's file starts with declare module '@seedcord/gateway', and an http bot's starts with declare module '@seedcord/http'.
When to run it
The generated file only changes when codegen runs, so a stale one either misses a new key or still types a key you removed. Run seedcord codegen after you attach a plugin, remove one, or rename a key.
When you accept the prompt from seedcord dev to re-register your commands, it runs codegen too.
Once codegen has run, your editor offers db on this.core.
this.core.- applicationId
- bot
- bus
- config
- db
- rateLimiter
- rest
- shutdown
- startup
Whether the plugin has started when your handler runs is a separate question, which the lifecycle answers.