Skip to content

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.

TBindings extends Bindings = any

Custom environment bindings (e.g., Cloudflare Workers env)

TVariables extends Variables = any

Custom Hono variables

TPath extends string = "/"

The path type for the context

types.ts
import type { BaseHonocordEnv, BaseInteractionContext } from "honocord";
// Define your custom environment
import 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 type
export type MyContext = BaseInteractionContext<MyEnv, MyVariables>;
// index.ts
import { 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]);