Skip to content

Quick start

This page takes you from npx discord0 init to a /ping command that replies in your own Discord server. It uses the default Cloudflare Workers adapter and npm, but every step works the same way with the other adapters and with pnpm, Yarn, or Bun.

You need:

  • Node.js 22 or newer, or Bun 1.4.4 or newer. The discord0 CLI runs on Bun. The discord0 package installs a Bun binary as a dependency and uses it when Node.js starts the CLI, so you don’t have to install Bun yourself.
  • A Discord account and a server where you can add apps. A private test server works best. Create one from the + button in the Discord server list.
  • Optional: an HTTPS tunnel for local testing. discord0 dev --tunnel starts a Cloudflare Quick Tunnel for you. You can also run cloudflared or ngrok yourself.

Pick the host you plan to deploy to. You can switch later.

Create a project

npx discord0 init my-bot --adapter cloudflare

Generated discord0.config.ts

import adapter from "@discord0/adapter-cloudflare";
import { defineConfig } from "discord0";

export default defineConfig({
  entry: "src/index.ts",
  adapter: adapter(),
  guild: process.env.DISCORD_GUILD_ID,
  sync: {
    deploy: "global",
  },
});

Deferred work on Cloudflare Workers can run for 30 seconds after the response. Read the Cloudflare Workers page.

  1. Create the project and install its dependencies. For another host, add --adapter <name> to init, as the picker shows.

    Terminal window
    npx discord0 init my-bot
    cd my-bot
    npm install

    init copies a starter into my-bot but doesn’t install anything. Its package.json depends on discord0 and the adapter package at the CLI’s own version, such as ^0.1.0-alpha.0. The starter has one command in src/index.ts:

    src/index.ts
    import { Discord } from "discord0";
    const app = new Discord();
    app.command("ping", "Replies with Pong!", () => "Pong!");
    export default app;
  2. Copy .env.example to .env:

    Terminal window
    cp .env.example .env

    Then create a Discord application, add it to your test server, and fill in its credentials and your server ID. Credentials walks through each value.

  3. Start the local server with a Quick Tunnel:

    Terminal window
    npx discord0 dev --tunnel

    It prints the local endpoint and a public https://…/interactions URL, then registers /ping with your test server:

    Discord interactions listening at http://127.0.0.1:3000/interactions
    Tunnel ready. Paste this Interactions Endpoint URL into the Developer Portal:
    https://example.trycloudflare.com/interactions
    Synced 1 commands (guild 123456789012345678).
  4. In the Developer Portal, open your application’s General Information page and set Interactions Endpoint URL to the printed HTTPS URL. Save the change. Discord sends a signed test request, and the save succeeds only if discord0 dev answers it.

  5. In your test server, type /ping. The app replies Pong!

  • Local development covers hot reload, command sync, and tunnels in more detail.
  • Deploy puts the app on your host, so it keeps running when your computer is off.