Cloudflare Workers
Learn how to deploy Honocord on Cloudflare Workers.
Hono is designed (primarily) for Cloudflare Workers, while Honocord works well with handling async interactions automatically to fit within Workers’ limits.
Why Cloudflare Workers?
- Global edge deployment with low latency.
- Generous free tier (100k requests/day).
- No cold starts, instant scaling.
- Honocord auto-manages async via
waitUntil.
Cloudflare Workers example
Project Setup
Initialize
wrangler.jsoncWarning
Starting with v2.0.0 it is required to have the `compatibility_flags` present in your `wrangler.jsonc` for Honocord to work properly. There is one usage of `node:path` for the new uploading files feature, and without the `nodejs_compat` flag, Workers won't be able to resolve this module and will throw an error when building.Bot Entry Point
src/index.tsExample Handler
src/handlers.tsSecrets
Never use plain environment variables for sensitive data.
Or have an
.envfile and bulk upload your secrets with:Local Development
To expose your local environment publicly for Discord’s verification:
Production Deployment
Deploy
Register Commands
Run this locally, not on the Worker itself.
src/register.tspackage.jsonThen run with
pnpm register.Discord Setup
- In the Discord Developer Portal → Your App → General Information.
- Set Interactions Endpoint URL to your Worker URL (e.g.,
https://.../interactions). - Save changes. Discord will automatically send a POST request to verify the URL.
Type Safety (optional but recommended)
When you deploy on Workers, you should use the wrangler script cf-typegen automatically provided upon project creation.
This creates a worker-configuration.d.ts file which exports an Env interface which you can use in your project.
Usage in a handler:
Best Practices
- Use secrets only for sensitive data.
- Keep handlers lightweight (≤50ms CPU time on the free plan).
- Store data in Workers KV, D1, or Durable Objects.
- Monitor logs with
wrangler tail. - Update
compatibility_dateon a regular basis.
Common Issues
- CPU limit exceeded: Split heavy work or use Durable Objects. Alternatively, upgrade to the Workers Paid plan.
- Verification fails: Double-check your public key, ensure the URL is correct (including any path like
/interactions), and ensure the Worker is deployed. - Module not found: Ensure you are using the correct relative paths and file extensions in your imports.