Skip to content

June 23, 2026

Running a Discord Bot Serverless on Cloudflare Workers — A Vibe Coding Guide

CommunityDiscordEngineeringAI

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:

  1. Cost: Ongoing monthly server fees in the range of a few dollars to tens of dollars
  2. Operations: Monitoring, updates, and restarts to manage
  3. 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:

AspectGateway (WebSocket)Interactions Endpoint (HTTP)
CommunicationPersistent WebSocket connectionWaits for HTTP POST requests
HostingRequires always-on serverWorks serverless (Cloudflare Workers, etc.)
Event typesReceives all events (messages, reactions, etc.)Only slash commands and other interactions
Best forReaction monitoring, full message processingCommand responses, buttons, modals
Cost profileFixed cost for always-on serverNear-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:

  1. Create a project with npm create cloudflare@latest
  2. Create an app in the Discord Developer Portal and retrieve your Public Key, Application ID, and Bot Token
  3. Set your secret with wrangler secret put DISCORD_PUBLIC_KEY
  4. Deploy with wrangler deploy and paste the generated URL into Discord’s “Interactions Endpoint URL” field
  5. 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 caseExample slash commandHandler logic
Rule reference/rulesReturn channel-specific rules in an Embed
FAQ Bot/faq keywordReturn the answer matching the keyword
Application intake/applyShow a modal (form) and receive submissions
Schedule info/next-eventReturn the next event’s date and overview
LLM responses/ask questionCall 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 factorChoose off-the-shelfChoose Cloudflare Workers build
Feature generalityMEE6 / Carl-bot covers your needsCustom workflow, proprietary rules
Data ownershipExternal service management is fineNeed to own and control logs/data
Cost sensitivityMonthly Bot subscription is acceptableWant to keep costs near zero
Technical resourcesNo engineer availableCan 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.

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.