Skip to content

Credentials

Every Discord0 app needs a Discord application. Locally, the starter keeps its credentials in .env. discord0 dev, discord0 sync, discord0 task, and the command sync after discord0 deploy load .env and then .env.local. Your .env never leaves your machine. discord0 deploy doesn’t upload it or pass it to the provider’s CLI.

.env
# Loaded locally by discord0 dev and by command sync after discord0 deploy.
DISCORD_BOT_TOKEN=
# Required to verify signed Discord requests.
DISCORD_PUBLIC_KEY=
APPLICATION_ID=
# Your test server's ID; discord0 dev syncs commands to it as you edit.
DISCORD_GUILD_ID=
  1. Open the Discord Developer Portal and select New Application. Give it a name and create it.
  2. On General Information, copy Application ID into APPLICATION_ID and Public Key into DISCORD_PUBLIC_KEY.
  3. On Bot, select Reset Token and copy the token into DISCORD_BOT_TOKEN. Discord shows it only once. Treat it like a password.

APPLICATION_ID is optional. When it’s empty, command sync looks up the application from the bot token.

  1. On Installation, make sure Guild Install is checked and that its scopes include applications.commands.
  2. Open the Install Link in your browser and add the app to your test server.

Commands work over HTTP interactions, so the app doesn’t need the bot scope for /ping. Add it when your handlers call Discord APIs that need a bot user in the server.

  1. In Discord, open User Settings → Advanced and turn on Developer Mode.
  2. Right-click your test server’s icon and select Copy Server ID.
  3. Paste it into DISCORD_GUILD_ID.

With a server ID set, discord0 dev registers your commands with that server only. Server commands update instantly, while global commands can take a while to reach every server.

In production, the app reads DISCORD_PUBLIC_KEY and DISCORD_BOT_TOKEN from the host’s environment, which you set with the provider. Deploy shows how for each host. The app doesn’t need DISCORD_GUILD_ID or APPLICATION_ID in production.

To read the credentials from somewhere else, such as variables with other names, pass them to new Discord():

import { Discord } from "discord0";
const app = new Discord({
publicKey: process.env.STAGING_PUBLIC_KEY,
token: process.env.STAGING_BOT_TOKEN,
});

To pass Worker bindings instead, see Cloudflare Workers.