A modern Discord.js starter template featuring CommandKit for command handling, database integration, and a clean project structure.
- CommandKit Integration: Modern command and event handling system
- Database Support: Built-in SQLite and JSON database support using st.db
- Sequelize ORM: Advanced database operations with Sequelize
- YAML Configuration: Easy configuration management
- Event System: Organized event handling structure
- Validation System: Built-in user role validation with Components V2
- TypeScript Support: Full TypeScript definitions for CommandKit
- Modular Architecture: Clean separation of concerns
- Automatic Database Sync: Database tables are automatically synchronized on startup
βββ src/
β βββ Commands/ # Slash commands
β β βββ Ping.js # Example ping command with TypeScript annotations
β βββ Events/ # Discord events
β β βββ clientReady/ # Bot ready events
β β β βββ ready.js # Bot ready event handler
β β βββ messageCreate/ # Message events
β β βββ hi.js # Message event handler example
β βββ Database/ # Database configuration
β β βββ Config/ # Database configs
β β β βββ index.js # Database exports
β β β βββ Example.js # Example database config
β β β βββ Sequelize.js # Sequelize configuration
β β β βββ YamlConfig.js # YAML configuration
β β βββ Data/ # Database files
β β β βββ Example.json # Example database data
β β βββ Helpers/ # Database helper functions
β β β βββ index.js # Helper exports
β β βββ Models/ # Database models
β β βββ User.js # User model with Sequelize
β βββ Validations/ # Command validations
β β βββ userRoles.js # User role validation with Components V2
β βββ Utils/ # Utility functions
βββ Config.yaml # Bot configuration
βββ index.js # Application entry point
βββ package.json # Dependencies
-
Clone the repository
git clone https://github.com/AboMeezO/D.js-Starter-Files cd D.js-Starter-Files -
Install dependencies
npm install
-
Configure your bot
- Open
Config.yaml - Add your Discord bot token:
Token: YOUR_BOT_TOKEN_HERE
- Open
-
Start the bot
npm start
Edit the Config.yaml file and add your Discord bot token:
Token: your_discord_bot_token_hereThe template includes multiple database systems:
- YAML Config: For bot configuration (Config.yaml)
- Example Database: Additional database for examples (src/Database/Data/Example.json)
Commands are located in src/Commands/. Here's the structure:
export default {
/**
* @type {import('commandkit').CommandData}
*/
data: {
name: "commandname",
description: "Command description",
},
/**
*
* @param {import('commandkit').SlashCommandProps} param0
*/
run: async ({ interaction, client, handler }) => {
await interaction.reply("Command response!");
},
/**
* @type {import('commandkit').CommandOptions}
*/
options: {
botPermissions: [],
userPermissions: [],
deleted: false,
devOnly: false,
guildOnly: false,
},
};botPermissions: Required bot permissionsuserPermissions: Required user permissionsdeleted: Whether the command is deleteddevOnly: Restrict to developers onlyguildOnly: Restrict to guilds only
Events are located in src/Events/. Create folders for event types and add your event files:
export default (client) => {
console.log(`Bot is ready! Logged in as ${client.user.tag}`);
};/**
* @param {import('discord.js').Message} message
* @param {import('discord.js').Client} client
*/
export default async (message, client) => {
if (message.content !== "hi" || message.author.bot) return;
await message.reply("hey");
};The template includes a user role validation system in src/Validations/userRoles.js using Discord.js Components V2. Add it to your command options:
options: {
userRoles: ["role_id_1", "role_id_2"], // Required role IDs
}The validation system uses Components V2 for enhanced user experience:
import {
ContainerBuilder,
MessageFlags,
SeparatorBuilder,
SeparatorSpacingSize,
TextDisplayBuilder,
} from "discord.js";
/**
* @param {import('commandkit').ValidationFunctionProps} param0
*/
export default function ({ interaction, commandObj }) {
const requiredRoles = new Set(commandObj.options?.userRoles);
if (!requiredRoles.size) return false;
const hasRequiredRole = interaction.member.roles.cache.some((role) =>
requiredRoles.has(role.id)
);
if (!hasRequiredRole) {
interaction.reply({
flags: [MessageFlags.Ephemeral, MessageFlags.IsComponentsV2],
components: [
new ContainerBuilder()
.addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`## β **Insufficient Permissions**`
)
)
.addSeparatorComponents(
new SeparatorBuilder().setSpacing(SeparatorSpacingSize.Large)
)
.addTextDisplayComponents(
new TextDisplayBuilder().setContent(
`You need the following roles:\n\n${[...requiredRoles]
.map((role) => `β’ <@&${role}>`)
.join("\n")}`
)
),
],
});
return true;
}
return false;
}The template includes multiple database systems for different use cases:
import { YamlConfig } from "./Database/index.js";
// Get configuration
const token = await YamlConfig.get("Token");
// Set configuration
await YamlConfig.set("Key", "Value");import { Example } from "./Database/index.js";
// Example Database
await Example.set("exampleKey", "exampleValue");
const exampleData = await Example.get("exampleKey");The template includes Sequelize for advanced database operations:
import { sequelize, Users } from "./Database/index.js";
// Database initialization (handled automatically in app.js)
await sequelize.sync();
// Create a new user
const newUser = await Users.create({
id: "123456789",
username: "example_user",
level: "1",
});
// Find a user
const user = await Users.findOne({
where: { id: "123456789" },
});
// Update a user
await Users.update({ level: "2" }, { where: { id: "123456789" } });
// Delete a user
await Users.destroy({
where: { id: "123456789" },
});The included User model provides a foundation for user management:
import { DataTypes } from "sequelize";
import { sequelize } from "../Config/index.js";
const Users = sequelize.define("users", {
id: {
primaryKey: true,
unique: true,
type: DataTypes.STRING,
},
username: {
type: DataTypes.STRING,
allowNull: false,
},
level: {
type: DataTypes.STRING,
defaultValue: "0",
allowNull: false,
},
});The template includes a modular app class for easy bot management:
import app from "./src/app.js";
// Initialize with existing client
const bot = new app({ client: yourClient });
// Initialize with token (creates new client)
const bot = new app({ token: "your_bot_token" });
// Start the bot
await bot.Start();The app class automatically handles database synchronization:
async initDatabase() {
await sequelize.sync();
}This ensures all database tables are created and synchronized when the bot starts.
- discord.js: Discord API wrapper
- commandkit: Command and event handler
- st.db: Database management
- sequelize: SQL ORM
- sqlite3: SQLite database driver
- zod: Schema validation
The template includes nodemon for development:
npm run devNodemon is configured to ignore database files during development to prevent unnecessary restarts.
npm start: Start the botnpm run dev: Start in development mode with auto-restartnpm test: Run tests (placeholder)
- Fork the repository
- Create a feature branch
- Make your changes
- Submit a pull request
This project is licensed under the ISC License.
Created by @AboTasneem
Note: Remember to keep your bot token secure and never commit it to version control!