FlowCord
The main entry point for the framework. Manages menu registration, interaction handling, and active session lifecycle.
import { FlowCord } from '@flowcord/core';
Constructor
new FlowCord(config: FlowCordConfig)
FlowCordConfig
| Option | Type | Default | Description |
|---|---|---|---|
client | Client<true> | Required | A logged-in Discord.js client |
timeout | number | 120000 | Session timeout in milliseconds |
enableTracing | boolean | false | Enable navigation event recording via NavigationTracer |
onError | (session, error) => Promise<void> | Built-in error embed | Custom error handler for unhandled session errors |
Example:
const flowcord = new FlowCord({
client,
timeout: 60_000,
enableTracing: process.env.NODE_ENV === 'development',
onError: async (session, error) => {
console.error(`[${session.id}]`, error);
},
});
Methods
registerMenu(name, factory)
registerMenu(name: string, factory: CreateMenuDefinitionFn): void
Registers a menu definition factory under the given name. The factory is called each time a new session opens that menu.
flowcord.registerMenu('settings', (session) =>
new MenuBuilder(session, 'settings')
.setEmbeds(/* ... */)
.setButtons(/* ... */)
.build()
);
handleInteraction(interaction, menuName, options?)
handleInteraction(
interaction: ChatInputCommandInteraction,
menuName: string,
options?: Record<string, unknown>
): Promise<void>
Creates a new session for the slash command interaction and opens the specified menu. options are passed as ctx.options in the menu's callbacks.
client.on('interactionCreate', async (interaction) => {
if (!interaction.isChatInputCommand()) return;
await flowcord.handleInteraction(interaction, interaction.commandName);
});
routeComponentInteraction(interaction)
routeComponentInteraction(interaction: MessageComponentInteraction): boolean
Routes a component interaction to the correct active session. Returns true if the interaction was matched to a session, false otherwise.
isFlowCordInteraction(customId)
isFlowCordInteraction(customId: string): boolean
Returns true if the custom ID belongs to an active FlowCord session. Useful for conditional routing in the interactionCreate handler.
getSession(sessionId)
getSession(sessionId: string): MenuSession | undefined
Returns the active session with the given ID, or undefined if not found. Primarily for debugging and testing.
Properties
engine
readonly engine: MenuEngine
The underlying MenuEngine instance. Exposes menuRegistry, hookRegistry, actionRegistry, and tracer for advanced use.
// Register a global hook
flowcord.engine.hookRegistry.register('onEnter', async (ctx) => {
console.log(`Entered: ${ctx.menu.name}`);
});
// Access navigation tracer
const events = flowcord.engine.tracer.events;
activeSessionCount
readonly activeSessionCount: number
Number of currently active sessions.
client
readonly client: Client<true>
The Discord.js client passed in the config.