Getting Started

Installation

Get started with djs-core.

From quickstart

Create github repo from template

Go to the quickstart repository and click on the Use this template button.

Install dependencies

Terminal
bun install

Setup environment variables

Rename the .env.example file to .env and set your Discord bot token (Discord Developer Portal):

TOKEN=your_discord_bot_token

Start your bot

Terminal
bun run start

From scratch

Set up a new djs-core project from scratch with complete control over your project structure.

Initialize your project

Create a new Bun project:

Terminal
bun init

This creates a basic package.json and initializes your project structure.

Install dependencies

Install djs-core packages:

Terminal
bun i -D @djs-core/dev
bun i @djs-core/runtime
  • @djs-core/dev is a dev dependency providing build tools and CLI commands
  • @djs-core/runtime is the runtime library containing the framework logic
  • Make sure you also have discord.js installed: bun i discord.js

Add scripts to package.json

Add the following scripts to your package.json:

package.json
{
  "scripts": {
    "dev": "djs-core dev",
    "build": "djs-core build",
    "start": "djs-core start"
  }
}
dev
script
Runs the bot in development mode with hot reload - automatically restarts when files change
build
script
Compiles TypeScript to JavaScript in the dist/ folder for production
start
script
Runs the compiled bot from the dist/ folder (use after build)

Create configuration file

Create a djs.config.ts file in your project root:

djs.config.ts
import type { Config } from "@djs-core/dev";

if (!process.env.TOKEN) {
  throw new Error("TOKEN environment variable is required");
}

export default {
  token: process.env.TOKEN,
  servers: ["YOUR_GUILD_ID"],
} satisfies Config;
token
string
Your Discord bot token from the Discord Developer Portal
servers
string[]
Array of guild (server) IDs where commands should be registered. Use an empty array [] for global commands (takes up to 1 hour to propagate).
Never commit your bot token to version control! Store it in a .env file and add .env to your .gitignore.

Setup environment variables

Create a .env file in your project root:

.env
TOKEN=your_discord_bot_token_here

Make sure to add .env to your .gitignore:

.gitignore
.env
node_modules/
dist/

Create your first command

Create the directory structure and your first command:

src/interactions/commands/ping.ts
import { Command } from "@djs-core/runtime";

export default new Command()
  .setDescription("Ping the bot")
  .run(async (interaction) => {
    await interaction.reply("Pong!");
  });
The command name is automatically derived from the file path. src/interactions/commands/ping.ts becomes /ping in Discord.

Start your bot

Run your bot in development mode:

Terminal
bun run dev

Your bot should now be online and the /ping command should be available in Discord!

In development mode, commands are automatically registered when the bot starts. You'll see console output indicating which commands were registered.

Next Steps

Now that your bot is set up, here's what to explore next:

Project Structure

Learn about the directory structure and how to organize your bot's code.

Commands

Create slash commands with options, autocomplete, and more advanced features.

Context Menus

Add right-click commands for users and messages.

Components

Create reusable buttons, modals, and select menus to enhance your interactions.