Installation
Get started with djs-core.
From quickstart
Create github repo from template
Go to the quickstart repository and click on the
Use this templatebutton.Install dependencies
Terminal window bun installSetup environment variables
Rename the
.env.examplefile to.envand set your Discord bot token (Discord Developer Portal):Terminal window TOKEN=your_discord_bot_tokenStart your bot
Terminal window 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 window bun initThis creates a basic
package.jsonand initializes your project structure.Install dependencies
Install djs-core packages:
Terminal window bun i -D @djs-core/devbun i @djs-core/runtime discord.js@djs-core/devis a dev dependency providing build tools and CLI commands@djs-core/runtimeis the runtime library containing the framework logic- Make sure you also have
discord.jsinstalled:bun i discord.js
Add scripts to package.json
Add the following scripts to your
package.json:{"scripts": {"dev": "djs-core dev","build": "djs-core build","start": "djs-core start","check": "djs-core check","test": "djs-core test"}}devscriptRuns the bot in development mode with hot reload for handlers under
src/(restart manually afterdjs.config.tschanges)buildscriptCompiles TypeScript to JavaScript in the
dist/folder for productionstartscriptRuns the compiled bot from the
dist/folder (use afterbuild)checkscriptLints
src/for djs-core anti-patterns (djs-core check)testscriptRuns colocated
bun:testsuites viadjs-core testCreate configuration file
Create a
djs.config.tsfile in your project root: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;tokenstringYour Discord bot token from the Discord Developer Portal
serversstring[]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
.envfile and add.envto your.gitignore.Setup environment variables
Create a
.envfile in your project root:TOKEN=your_discord_bot_token_hereMake sure to add
.envto your.gitignore:.envnode_modules/dist/Create your first command
Create the directory structure and your first command at
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.tsbecomes/pingin Discord.Start your bot
Run your bot in development mode:
Terminal window bun run devYour bot should now be online and the
/pingcommand 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:
Learn about the directory structure and how to organize your bot’s code.
CommandsCreate slash commands with options, autocomplete, and more advanced features.
Context MenusAdd right-click commands for users and messages.
ComponentsCreate reusable buttons, modals, and select menus to enhance your interactions.