Skip to content

@bight-ts/core — Plugins

import {
definePlugin,
definePlugins,
type BightPlugin,
type BightPluginSetup,
} from "@bight-ts/core";

Defines a plugin with lifecycle hooks.

PropertyTypeRequiredDescription
namestringYesPlugin identifier (visible in diagnostics)
setup(input: BightPluginSetup) => voidNoRuns during initialization. Can register commands, handlers, preconditions, and events.
beforeLogin(input: BightPluginLifecycle) => voidNoRuns after all plugins are set up, before connecting to Discord
afterLogin(input: BightPluginLifecycle) => voidNoRuns after the bot is online

Available inside the setup hook.

PropertyTypeDescription
clientClientThe Discord.js client
contextBightContext<TServices>The app context
registryBightRegistryThe command/handler registry
pluginNamesstring[]Names of all registered plugins
getEventCount() => numberCurrent total event listener count
diagnosticsBightDiagnosticsHubThe diagnostics hub
addCommand(command: BotCommand) => voidRegister a command
addPrecondition(precondition: BightPrecondition) => voidRegister a precondition
addGlobalPrecondition(precondition: BightGlobalPrecondition) => voidRegister a global precondition
addButtonHandler(handler: ButtonHandler) => voidRegister a button handler
addModalHandler(handler: ModalHandler) => voidRegister a modal handler
addSelectMenuHandler(handler: SelectMenuHandler) => voidRegister a select menu handler
addEvent(event: BotEvent) => voidRegister an event listener

Available inside beforeLogin and afterLogin hooks. Same as BightPluginSetup but without the add* methods — registration is only allowed during setup.

Filters out falsey values from a plugin array, enabling conditional inclusion:

const plugins = definePlugins([
devtoolsPlugin,
process.env.ENABLE_SCHEDULER === "true" && schedulerPlugin,
]);
// falsey entries are removed

Base options type for official Bight plugins.

PropertyTypeDescription
enabledbooleanToggle the plugin on or off (default: true)
namestringOverride the plugin name
loggerScopestringLogger scope for this plugin