Skip to content

Honocord

Defined in: Honocord.ts:86

new Honocord(__namedParameters?): Honocord

Defined in: Honocord.ts:138

HonocordOptions = {}

Honocord

clearMiddleware(): this

Defined in: Honocord.ts:769

Clears all registered middleware functions.

this

The Honocord instance for chaining.


getApp(options?): Hono<{ Variables: BaseVariables; }, BlankSchema, "/">

Defined in: Honocord.ts:608

Returns a Hono App instance with the interaction handler mounted at the root path and a GET Handler for all paths, which returns a simple Health response.

HonocordAppOptions = {}

Hono<{ Variables: BaseVariables; }, BlankSchema, "/">

import { Honocord } from "honocord";
const honoCord = new Honocord();
export default honoCord.getApp();
// Supports both "/" and "/interactions" for the interactions handler, if any are loaded
// And `/webhook` for the webhook handler if any are loaded

interactionsHandler(c): Promise<Response & TypedResponse<"Bad request signature.", 401, "text"> | Response & TypedResponse<"No interaction found.", 400, "text"> | JSONRespondReturn<{ }, 202> | Response & TypedResponse<"Internal server error.", 500, "text"> | JSONRespondReturn<{ type: InteractionResponseType; }, ContentfulStatusCode> | undefined>

Defined in: Honocord.ts:551

Returns a Hono handler for POST Requests handling Discord interactions.

BaseInteractionContext

Promise<Response & TypedResponse<"Bad request signature.", 401, "text"> | Response & TypedResponse<"No interaction found.", 400, "text"> | JSONRespondReturn<{ }, 202> | Response & TypedResponse<"Internal server error.", 500, "text"> | JSONRespondReturn<{ type: InteractionResponseType; }, ContentfulStatusCode> | undefined>

import { Hono } from "hono";
import { Honocord } from "honocord";
const app = new Hono();
const bot = new Honocord();
app.get("/", (c) => c.text("🔥 Honocord is running!"));
app.post("/interactions", bot.interactionsHandler);
export default app;

loadHandlers(…handlers): void

Defined in: Honocord.ts:150

Registers handlers for interactions.

…FlatOrNestedArray<AnyHandler>

Array of CommandHandler, ComponentHandler, or ModalHandler instances

For an example of usage, see the Example Repository.

void


use<Context>(…middleware): this

Defined in: Honocord.ts:660

Registers a middleware function to process interaction contexts.

Middleware receives the Hono context and a next callback:

  • Access/modify context variables via c.get() and c.set()
  • Access the interaction object via c.var.command, c.var.component, c.var.modal, or c.var.autocomplete
  • Access environment bindings via c.env
  • Call await next() to continue to the next middleware or handler

The context is passed by reference, so all modifications persist through the middleware chain and into handlers.

Context extends BaseInteractionContext = BaseInteractionContext

…MiddlewareFunction<Context>[]

The middleware function(s) to register.

this

The Honocord instance for chaining.

bot.use(async (c, next) => {
// Set custom data in context
c.set('startTime', Date.now());
// Continue to next middleware/handler
// you can also return next() directly if no post-processing is needed
await next();
// Code here runs after the handler completes
console.log('Duration:', Date.now() - c.get('startTime'));
});

webhookHandler(c): Promise<any>

Defined in: Honocord.ts:684

Returns a Hono handler for POST requests handling Discord webhook events.

On Cloudflare Workers, webhook events are processed asynchronously using waitUntil, allowing immediate response to Discord while extending the worker’s lifetime to complete processing.

Context

Promise<any>

import { Hono } from "hono";
import { Honocord } from "honocord";
const app = new Hono();
const bot = new Honocord();
app.post("/webhook", bot.webhookHandler);
export default app;

withCache<TheEnv>(factory): this

Defined in: Honocord.ts:746

Registers a cache adapter factory for use throughout the bot. The factory receives the request environment and returns a BaseCacheAdapter instance.

On Cloudflare Workers, use DurableObjectCacheAdapter. On self-hosted environments, use MemoryCacheAdapter, MongoCacheAdapter, or RedisAdapter.

TheEnv = any

(env) => BaseCacheAdapter

A function that receives the environment and returns a cache adapter.

this

The Honocord instance for chaining.

// Cloudflare Workers
bot.withCache((env) => new DurableObjectCacheAdapter(env.MY_CACHE));
// Self-hosted (pre-initialized)
const cache = new MongoCacheAdapter(process.env.MONGO_URI!);
await cache.connect();
bot.withCache(() => cache);