BaseInteractionContext
Type Alias: BaseInteractionContext<TBindings, TVariables, TPath>
Section titled “Type Alias: BaseInteractionContext<TBindings, TVariables, TPath>”BaseInteractionContext<
TBindings,TVariables,TPath> =Context<{Bindings:TBindings;Variables:TVariables&BaseVariables; },TPath,any>
Defined in: types/context.ts:94
Generic context type that users can extend for type-safe access to environment bindings and variables.
Type Parameters
Section titled “Type Parameters”TBindings
Section titled “TBindings”TBindings extends Bindings = any
Custom environment bindings (e.g., Cloudflare Workers env)
TVariables
Section titled “TVariables”TVariables extends Variables = any
Custom Hono variables
TPath extends string = "/"
The path type for the context
Example
Section titled “Example”import type { BaseHonocordEnv, BaseInteractionContext } from "honocord";
// Define your custom environmentimport type { BaseHonocordEnv, BaseInteractionContext } from "honocord";
// Define your custom environment bindings (e.g., Cloudflare Workers env)export interface MyEnv { DISCORD_TOKEN: string; DISCORD_PUBLIC_KEY: string; DATABASE: D1Database; // Example Cloudflare D1}
// Define your custom Hono variables (can be populated by middleware)export interface MyVariables { user_id: string; is_admin: boolean;}
// Create a reusable context typeexport type MyContext = BaseInteractionContext<MyEnv, MyVariables>;
// index.tsimport { Honocord, SlashCommandHandler } from "honocord";import type { MyContext } from "./types";
const bot = new Honocord();
const command = new SlashCommandHandler() .setName("query") .setDescription("Query the database");
command.addHandler(async (interaction: MyContext) => { // Type-safe access to your environment const db = interaction.env.DATABASE; const result = await db.prepare("SELECT * FROM users").all(); await interaction.reply(`Found ${result.results.length} users`);});
bot.loadHandlers([command]);