PopiiPlugin
Popii / PopiiPlugin
Interface: PopiiPlugin<TState>
Section titled “Interface: PopiiPlugin<TState>”Defined in: types.ts:534
The interface all Popii plugins must implement.
A plugin is a plain object returned from a factory function. It hooks into the client
lifecycle via setup, ready, reload, and cleanup, and can also intercept every
command execution via onCommandExecute and onCommandError.
Example
Section titled “Example”import type { PopiiPlugin } from "popii";
export function myPlugin(): PopiiPlugin { return { name: "my-plugin", setup(client) { // runs once at startup — register listeners, create DB tables, etc. }, ready(client) { // runs after Discord connects — safe to use client.discord.guilds.cache }, cleanup(client) { // runs on graceful shutdown — clear intervals, close connections } };}Type Parameters
Section titled “Type Parameters”TState
Section titled “TState”TState = any
Methods
Section titled “Methods”setup()?
Section titled “setup()?”
optionalsetup(client):void|Promise<void>
Defined in: types.ts:610
Runs once at startup, before connecting to Discord.
Register event listeners, create DB tables, and perform one-time initialisation here.
Optional when the plugin only provides commands or settingsSchema.
Parameters
Section titled “Parameters”client
Section titled “client”PopiiClient<TState>
Returns
Section titled “Returns”void | Promise<void>
ready()?
Section titled “ready()?”
optionalready(client):void|Promise<void>
Defined in: types.ts:612
Runs after the bot successfully connects to Discord. Safe to access guild and user caches.
Parameters
Section titled “Parameters”client
Section titled “client”PopiiClient<TState>
Returns
Section titled “Returns”void | Promise<void>
reload()?
Section titled “reload()?”
optionalreload(client):void|Promise<void>
Defined in: types.ts:614
Runs after a hot-reload. Re-wrap commands with middleware or refresh state here.
Parameters
Section titled “Parameters”client
Section titled “client”PopiiClient<TState>
Returns
Section titled “Returns”void | Promise<void>
cleanup()?
Section titled “cleanup()?”
optionalcleanup(client):void|Promise<void>
Defined in: types.ts:616
Runs on graceful shutdown. Clear intervals and close external connections here.
Parameters
Section titled “Parameters”client
Section titled “client”PopiiClient<TState>
Returns
Section titled “Returns”void | Promise<void>
onCommandExecute()?
Section titled “onCommandExecute()?”
optionalonCommandExecute(pop,command):void|Promise<void>
Defined in: types.ts:618
Called before every command or snap executes. Useful for analytics and tracing.
Parameters
Section titled “Parameters”Pop<TState>
command
Section titled “command”PopiiCommandDefinition<TState, any, PopiiLocals & Record<string, any>> | PopiiComponentDefinition<TState, any, PopiiLocals & Record<string, any>>
Returns
Section titled “Returns”void | Promise<void>
onCommandError()?
Section titled “onCommandError()?”
optionalonCommandError(error,pop):void|Promise<void>
Defined in: types.ts:620
Called when a command or snap throws an unhandled error.
Parameters
Section titled “Parameters”unknown
Pop<TState>
Returns
Section titled “Returns”void | Promise<void>
onContextCreate()?
Section titled “onContextCreate()?”
optionalonContextCreate(pop):void
Defined in: types.ts:622
Called when a new pop context is created. Inject data into the context here.
Parameters
Section titled “Parameters”EventPop<TState>
Returns
Section titled “Returns”void
health()?
Section titled “health()?”
optionalhealth(): {ok:boolean;message?:string; } |Promise<{ok:boolean;message?:string; }>
Defined in: types.ts:627
Optional health check. Called by /health and popii doctor at runtime.
Return { ok: false, message: "why" } to signal degraded state.
Returns
Section titled “Returns”{ ok: boolean; message?: string; } | Promise<{ ok: boolean; message?: string; }>
onConfigChange()?
Section titled “onConfigChange()?”
optionalonConfigChange(newOptions):boolean|void|Promise<boolean|void>
Defined in: types.ts:632
Called when the bot owner updates plugin options at runtime via the dashboard. Receives the new merged options object. Return false to reject the change.
Parameters
Section titled “Parameters”newOptions
Section titled “newOptions”Record<string, any>
Returns
Section titled “Returns”boolean | void | Promise<boolean | void>
Properties
Section titled “Properties”name:
string
Defined in: types.ts:535
manifest?
Section titled “manifest?”
optionalmanifest?:PluginManifest
Defined in: types.ts:537
Popii 1.0 lifecycle and security metadata. Added automatically to legacy built-ins.
configSchema?
Section titled “configSchema?”
optionalconfigSchema?:ZodType<unknown,unknown,$ZodTypeInternals<unknown,unknown>>
Defined in: types.ts:539
Configuration boundary used by the 1.0 plugin runtime.
dashboard?
Section titled “dashboard?”
optionaldashboard?:DashboardContribution|DashboardContributionV2
Defined in: types.ts:541
Safe, typed pages and actions contributed to the Cakemix dashboard.
version?
Section titled “version?”
optionalversion?:string
Defined in: types.ts:546
The semantic version of this plugin (e.g. "1.2.0").
Used by other plugins to declare version-range requirements in requires.
requires?
Section titled “requires?”
optionalrequires?:string[]
Defined in: types.ts:553
Plugin names that must be loaded before this plugin.
Append @<range> to enforce a semver constraint on the required plugin’s version
(e.g. "popii-sqlite@>=2.0.0", "popii-sqlite@^1.0.0").
Popii throws at startup if any listed plugin is missing or out of range.
requiresOneOf?
Section titled “requiresOneOf?”
optionalrequiresOneOf?:string[][]
Defined in: types.ts:562
Each inner array is an OR group — at least one name from each group must be loaded. Use this when a plugin can work with any one of several alternatives (e.g. SQLite or Mongoose). Popii throws at startup if no plugin from an inner array is present.
Example
Section titled “Example”requiresOneOf: [["popii-sqlite", "popii-mongoose"]]conflicts?
Section titled “conflicts?”
optionalconflicts?:string[]
Defined in: types.ts:567
Plugin names this plugin cannot coexist with. Popii throws at startup if any listed plugin is also present.
priority?
Section titled “priority?”
optionalpriority?:number
Defined in: types.ts:572
Execution order during the setup lifecycle. Higher values run first.
Default
Section titled “Default”0settingsSchema?
Section titled “settingsSchema?”
optionalsettingsSchema?:PopiiServerSetting[]
Defined in: types.ts:577
Declarative per-guild settings exposed in the web dashboard’s server settings form. The category defaults to the plugin name if omitted.
intents?
Section titled “intents?”
optionalintents?:number[]
Defined in: types.ts:583
Gateway intents this plugin requires. Popii ORs these into the auto-detected intent set
so you never need to manually configure intents for built-in plugins.
Use GatewayIntentBits values (numbers).
partials?
Section titled “partials?”
optionalpartials?:Partials[]
Defined in: types.ts:587
Discord.js Partials this plugin requires. Merged into the auto-detected partials set.
commands?
Section titled “commands?”
optionalcommands?:PopiiCommandDefinition<TState,any,PopiiLocals&Record<string,any>>[]
Defined in: types.ts:604
Commands bundled with this plugin. Registered automatically on startup and after every
hot-reload. Commands in the user’s src/commands/ directory with the same name always
take priority, giving users a clean override path without touching the plugin source.
Use pluginCommands.disable in your bot config to suppress individual commands, or
pluginCommands.overrides to patch them without a full replacement.
Example
Section titled “Example”import { command } from 'popii-framework';commands: [ command({ name: 'ping', description: 'Ping the bot', do: (pop) => pop.reply('Pong!') })]