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.
Before you start
Section titled “Before you start”You need:
- Node.js 22 or newer, or Bun 1.4.4 or
newer. The
discord0CLI runs on Bun. Thediscord0package 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 --tunnelstarts a Cloudflare Quick Tunnel for you. You can also runcloudflaredor ngrok yourself.
Create a project
Section titled “Create a project”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.
-
Create the project and install its dependencies. For another host, add
--adapter <name>toinit, as the picker shows.Terminal window npx discord0 init my-botcd my-botnpm installinitcopies a starter intomy-botbut doesn’t install anything. Itspackage.jsondepends ondiscord0and the adapter package at the CLI’s own version, such as^0.1.0-alpha.0. The starter has one command insrc/index.ts:src/index.ts import { Discord } from "discord0";const app = new Discord();app.command("ping", "Replies with Pong!", () => "Pong!");export default app; -
Copy
.env.exampleto.env:Terminal window cp .env.example .envThen create a Discord application, add it to your test server, and fill in its credentials and your server ID. Credentials walks through each value.
-
Start the local server with a Quick Tunnel:
Terminal window npx discord0 dev --tunnelIt prints the local endpoint and a public
https://…/interactionsURL, then registers/pingwith your test server:Discord interactions listening at http://127.0.0.1:3000/interactionsTunnel ready. Paste this Interactions Endpoint URL into the Developer Portal:https://example.trycloudflare.com/interactionsSynced 1 commands (guild 123456789012345678). -
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 devanswers it. -
In your test server, type
/ping. The app replies Pong!
Next steps
Section titled “Next steps”- 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.