bun init
.
terminal
Now install Discord.js.
terminal
Before we go further, we need to go to the Discord developer portal, login/signup, create a new Application, then create a new Bot within that application. Follow the official guide for step-by-step instructions.
Once complete, you’ll be presented with your bot’s private key. Let’s add this to a file called
.env.local
. Bun automatically reads this file and loads it into process.env
.
This is an example token that has already been invalidated.
.env.local
Be sure to add
.env.local
to your .gitignore
! It is dangerous to check your bot’s private key into version control.
.gitignore
Now let’s actually write our bot in a new file called
bot.ts
.
Now we can run our bot with
bun run
. It may take a several seconds for the client to initialize the first time you run the file.
terminal
You’re up and running with a bare-bones Discord.js bot! This is a basic guide to setting up your bot with Bun; we recommend the official discord.js docs for complete information on the
discord.js
API.