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.
# 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=Create the application
Section titled “Create the application”- Open the Discord Developer Portal and select New Application. Give it a name and create it.
- On General Information, copy Application ID into
APPLICATION_IDand Public Key intoDISCORD_PUBLIC_KEY. - 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.
Add the application to your test server
Section titled “Add the application to your test server”- On Installation, make sure Guild Install is checked and that its
scopes include
applications.commands. - 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.
Find your test server ID
Section titled “Find your test server ID”- In Discord, open User Settings → Advanced and turn on Developer Mode.
- Right-click your test server’s icon and select Copy Server ID.
- 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.
Credentials in production
Section titled “Credentials in production”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.