Bun
Learn how to set up and deploy your Carbon bot using the Bun runtime, including development and production environments.
Setup
Automatic Setup
Quickly set up your Carbon bot with minimal configuration using the automatic setup guide.
Other Runtimes
Explore how to set up and deploy your Carbon bot using different runtimes.
Manual Setup
This is a continuation of the Basic Setup guide. If you haven't already, make sure to follow the steps in the guide before proceeding.
Create a Server
Using the @buape/carbon/adapters/bun
package, you can create a server to host your bot. This server will handle incoming interactions and route them to your bot.
Running in Development
Set Environment Variables
First things first, you'll need to grab your Discord application's secrets from the Developer Portal and paste them in your .env
file.
Set Up a Proxy
Discord requires a public URL to route interactions to your project. To achieve this, you'll need to set up a proxy. The simplest way to do this is by using localtunnel
. Once you have the public URL, you may want to set it as BASE_URL="<PUBLIC_URL>"
in your .env
file.
You can use the --subdomain
flag to specify a custom subdomain for your proxy.
Configure Portal URLs
Now that you have a public URL, navigate back to the Discord Developer Portal and set the "Interactions Endpoint URL" to <BASE_URL>/interactions
.
Invite your App
You'll need to invite your app to your server to interact with it. To do so, navigate to the Installation tab of your app in the Discord Developer Portal.
Deploy Your Commands to Discord
Finally, to deploy your commands to Discord, navigate to <BASE_URL>/deploy?secret=<DEPLOY_SECRET>
in your browser. This will send your command data to Discord to register them with your bot.
Deploying to Production
Prepare a Server
Since you're deploying a Bun project, you'll need a server to host your bot. You'll also need to set up Bun and Git on your server.
Initialize a Git Repository
You'll need to transfer your project files to your server, this can be done using Git and GitHub. To do this, initialize a new Git repository, commit your files and push them to GitHub. On your server you can then clone your repository.
Make sure not to commit your .env
file or any secrets to your repository.
Prepare Environment
Almost there! Now just like in development, you'll need to set up a proxy, configure your environment variables and set up your Discord app's URLs. Additionally, you'll need to install your dependencies using:
Start the Bot
Now that you've prepared your environment, you can finally build and start your bot using:
You may also want to set up a process manager like PM2 to keep your bot running in the background.
Reminder to deploy your commands to Discord using <BASE_URL>/deploy?secret=<DEPLOY_SECRET>
.
Last updated on