Creating a Discord.js Bot
If you already have a Discord bot programmed, simply head to the “Deploying with Nubo” section below.This documentation assumes that you have already registered a Discord application and bot via the discord developers portal.
Setup a new codebase
1
Initialize project
Using Bun? Use the blank template and rename your
index.ts
file to index.js
. At this moment, Bun is not directly supported with Nubo and Node will be used at runtime. Therefore, TypeScript isn’t supported by default.2
Install dotenv
The
dotenv
package will make variables stored in our .env available at runtime. This is required to register our commands.This step is not required if you are using Bun. This is because Bun automatically makes .env variables available at runtime. This is why we love Bun!
Registering our slash commands
For now, there isn’t a good way to securely handle environment variables at build time with Nubo. Therefore, we must register our commands locally. In the future, we will support build environment variables that will allow us to run this register command for every build automatically.1
Create a registerCommands.js file
This file will interact with the Discord API to register your slash commands.The contents of this file should look like:As we can see, this is registering one command: the “ping” command. Which, by our description simply replies with “pong”.
registerCommands.js
2
Create a .env file
Create a Input the following content to your
.env
file in the project’s root directory that will hold our secrets.Be sure to add this file to your
.gitignore
so that your secrets are not publicly exposed to your Git repository..env
file and replace with your application secrets:3
Register the commands
To register the commands, run the You should receive a success message in your terminal that looks like:
registerCommands.js
file:Programming the /ping
command
Create an index.js
file with the following content:
index.js
/ping
command.
To test this bot locally, simply run the following:
/ping
command.
Congratulations! You have successfully built a very basic Discord bot using discord.js
.
Push changes to GitHub
Stage all changes:Deploying with Nubo
1
Configuring start script
First we must create a start script that tells Nubo to run our bot as the default process for the container.Edit your
package.json
, and add a “scripts” section. Example:package.json
This start script does not change if you are using Bun. As the Bun runtime is not supported yet with Nubo.
2
Push your changes to GitHub
Stage all changes:Commit changes:Push to GitHub:
3
Deploy via the Nubo dashboard
Head over to the Nubo dashboard. You will need to create or select an existing Project.
Now, select the ”+ Frame” button
Next, choose your repository and click “Deploy”



4
Configure environment variables for secrets
Now that our Frame is deploying, the bot will not work until we provide our credentials.Head over to the Frame’s settings, and click “Environment variables”.
We will want to create two environment variables. Those being the following:
Now, select the “Redeploy” button to manually schedule a Frame deployment.

Key | Value |
---|---|
CLIENT_ID | The application ID for your bot |
TOKEN | The secret token for your bot |
The “key” names are assuming that you are using those keywords in your bot’s code. If they are named something else, change the key names.
