June 23, 2026
Running a Discord Bot Serverless on Cloudflare Workers — A Vibe Coding Guide
Why “no persistent server” is now the standard approach
As covered in What You Can Do with Discord Bot and API, self-built Bots need a hosting environment to run. The traditional approach used VPS instances or Docker containers running 24/7, but this created three problems:
- Cost: Ongoing monthly server fees in the range of a few dollars to tens of dollars
- Operations: Monitoring, updates, and restarts to manage
- Scaling: Needing excess capacity to handle traffic spikes (large events, etc.)
Cloudflare Workers’ serverless model solves all three. Your code runs on Cloudflare’s edge CDN (300+ locations worldwide) only when a request arrives. Each time Discord invokes a command, the Worker spins up, returns a response, and terminates — this “disposable execution” is the source of low cost and low operations.
Interactions Endpoint vs Gateway: the two architectures
Discord supports two Bot implementation architectures:
| Aspect | Gateway (WebSocket) | Interactions Endpoint (HTTP) |
|---|---|---|
| Communication | Persistent WebSocket connection | Waits for HTTP POST requests |
| Hosting | Requires always-on server | Works serverless (Cloudflare Workers, etc.) |
| Event types | Receives all events (messages, reactions, etc.) | Only slash commands and other interactions |
| Best for | Reaction monitoring, full message processing | Command responses, buttons, modals |
| Cost profile | Fixed cost for always-on server | Near-free within request-based billing |
Bots that monitor every message in every channel require Gateway. But the vast majority of community automation needs — letting users run commands, press buttons, fill out forms — can be covered entirely by the Interactions Endpoint approach.
Architecture overview
The Cloudflare Workers + Discord Bot setup works as follows:
User executes /hello
→ Discord sends POST request to Worker URL
→ Worker verifies Ed25519 signature (security)
→ Worker returns Embed as JSON
→ Discord displays the response
Signature verification is a Discord security requirement. It must always be implemented. The discord-interactions library handles this automatically.
Code example: a Worker that responds to slash commands
import {
InteractionResponseType,
InteractionType,
verifyKey,
} from 'discord-interactions';
export default {
async fetch(request: Request, env: Env): Promise<Response> {
if (request.method !== 'POST') {
return new Response('Method not allowed', { status: 405 });
}
// Ed25519 signature verification
const signature = request.headers.get('x-signature-ed25519') ?? '';
const timestamp = request.headers.get('x-signature-timestamp') ?? '';
const body = await request.text();
const isValid = await verifyKey(body, signature, timestamp, env.DISCORD_PUBLIC_KEY);
if (!isValid) {
return new Response('Bad request signature', { status: 401 });
}
const interaction = JSON.parse(body);
// Respond to Discord's ping (health check)
if (interaction.type === InteractionType.PING) {
return Response.json({ type: InteractionResponseType.PONG });
}
// Handle slash commands
if (interaction.type === InteractionType.APPLICATION_COMMAND) {
const { name } = interaction.data;
if (name === 'hello') {
return Response.json({
type: InteractionResponseType.CHANNEL_MESSAGE_WITH_SOURCE,
data: {
embeds: [
{
title: 'Hello!',
description: 'This is a Discord Bot running on Cloudflare Workers.',
color: 0x5865f2, // Discord Blurple
},
],
},
});
}
}
return new Response('Unknown interaction', { status: 400 });
},
};
interface Env {
DISCORD_PUBLIC_KEY: string;
}
wrangler.toml configuration:
name = "my-discord-bot"
main = "src/index.ts"
compatibility_date = "2024-11-01"
Set secrets (like DISCORD_PUBLIC_KEY) using the wrangler secret put DISCORD_PUBLIC_KEY command.
How to build it through vibe coding
Even without a dedicated software engineer, you can implement this Bot using AI coding tools (like Claude). The following prompt is a practical starting template:
I want to build a Discord Bot using the Cloudflare Workers
Interactions Endpoint approach. Requirements:
- TypeScript implementation
- Responds to slash command /welcome with an Embed welcome message
- Includes Ed25519 signature verification
- Uses the discord-interactions library
- Include the full wrangler.toml and package.json
Please provide the complete code and the step-by-step deploy
process (in the exact order of commands to run).
The deployment steps after receiving the code:
- Create a project with
npm create cloudflare@latest - Create an app in the Discord Developer Portal and retrieve your Public Key, Application ID, and Bot Token
- Set your secret with
wrangler secret put DISCORD_PUBLIC_KEY - Deploy with
wrangler deployand paste the generated URL into Discord’s “Interactions Endpoint URL” field - Register slash commands (run a one-time script, or register via the Discord Developer Portal)
Ask the AI to write the command registration script as well — it will save time.
Use case examples for community management
| Use case | Example slash command | Handler logic |
|---|---|---|
| Rule reference | /rules | Return channel-specific rules in an Embed |
| FAQ Bot | /faq keyword | Return the answer matching the keyword |
| Application intake | /apply | Show a modal (form) and receive submissions |
| Schedule info | /next-event | Return the next event’s date and overview |
| LLM responses | /ask question | Call Claude API and return the answer (requires deferred response) |
Note on deferred responses: Cloudflare Workers have execution time limits, and Discord requires an initial response within 3 seconds. For LLM API calls, use the deferred response pattern — first reply with “Thinking…”, then update the message via Webhook once the LLM response arrives.
When to use off-the-shelf Bots vs. Cloudflare Workers builds
As described in Setting Up a Discord Community, the practical approach is to start with off-the-shelf Bots, then migrate to self-built for specific pain points.
| Decision factor | Choose off-the-shelf | Choose Cloudflare Workers build |
|---|---|---|
| Feature generality | MEE6 / Carl-bot covers your needs | Custom workflow, proprietary rules |
| Data ownership | External service management is fine | Need to own and control logs/data |
| Cost sensitivity | Monthly Bot subscription is acceptable | Want to keep costs near zero |
| Technical resources | No engineer available | Can implement via vibe coding |
Summary
- The Interactions Endpoint approach on Cloudflare Workers lets you run a Discord Bot without any always-on server
- The free tier (100,000 requests/day) is sufficient for communities of up to ~1,000 active users
- Command responses, buttons, and modals — the core of most community automation — work fully in this architecture
- Vibe coding (AI-assisted development) makes implementation accessible even without a specialist engineer
- LLM integrations require the deferred response pattern, which can also be designed with AI assistance
If you’re interested in building Discord or Slack Bots in-house, or designing end-to-end community automation, see Rokuse’s Community Development Service. We support everything from requirements scoping to vibe coding guidance.
Related articles
Contact · Rokuse LLC
Continue this conversation about your community.
If a moment in this article made you wonder "what about ours?", send that exact question. It does not have to be polished — we will work the entry point out together.
Frequently asked questions
- Q. What changes when you run a Discord Bot on Cloudflare Workers?
- A. You no longer need a server that stays on 24/7. Cloudflare Workers executes your code on edge CDN nodes only when a request arrives. Discord sends interactions (such as slash command executions) as HTTP POST requests to your Worker URL, and the Worker responds with JSON. Compared to the Gateway approach where you keep a server running constantly, the cost drops to virtually zero (the free tier is sufficient), and operational overhead is dramatically reduced.
- Q. How many requests can the Cloudflare Workers free tier handle?
- A. The free plan allows 100,000 requests per day at no charge. For a community of 1,000 members using slash commands, this is typically more than enough. If your request volume grows, the Workers paid plan starts at $5/month (up to 10 million requests), which is far cheaper than a dedicated server.
- Q. When vibe coding a Bot, what should I tell the AI?
- A. Be specific about the platform, approach, command name, response format, and library. For example — "I want to build a Discord Bot using the Cloudflare Workers Interactions Endpoint approach. It should respond to a slash command /hello with an Embed greeting. Please write it in TypeScript using the discord-interactions library, and include the wrangler.toml setup as well." Once you have the code, also ask about error handling, rate limits, and edge cases.