A modern, scalable Discord bot template built with TypeScript, Discord.js v14, and SQLite. Features advanced command management, comprehensive logging, and a robust database system.
- β TypeScript Support - Full type safety and modern development experience
- β Advanced Command System - Automatic registration, hash tracking, and smart updates
- β Comprehensive Logging - Winston-based logging with file and console output
- β SQLite Database - Persistent storage with user stats, guild settings, and command tracking
- β Modern Architecture - Clean separation of concerns with handlers and utilities
- β Error Handling - Robust error handling and graceful degradation
- β Permission System - Built-in permission checking utilities
- β Embed Utilities - Pre-built embed templates for consistent UI
- β Development Tools - ESLint, Jest testing, and hot reloading
- Node.js v18.0.0 or higher
- TypeScript v5.0.0 or higher
- A Discord Bot application with proper intents
git clone https://github.com/OfficialAudite/discord-bot-template.git
cd discord-bot-templatenpm installCreate a .env file in the root directory:
# Bot Configuration
TOKEN=your-discord-bot-token
CLIENT_ID=your-discord-application-id
# Optional Settings
NODE_ENV=development
LOG_LEVEL=info# Development mode (with hot reload)
npm run dev
# Production build
npm run build
npm start
# Watch mode for development
npm run watchsrc/
βββ commands/ # Slash command definitions
β βββ ping.ts # Example ping command
β βββ info.ts # Bot/server info command
β βββ stats.ts # User statistics command
βββ events/ # Discord event handlers
β βββ ready.ts # Bot ready event
β βββ interactionCreate.ts
β βββ guildCreate.ts
β βββ guildDelete.ts
βββ handlers/ # Core system handlers
β βββ commandHandler.ts
β βββ eventHandler.ts
βββ database/ # Database management
β βββ database.ts # SQLite wrapper
βββ utils/ # Utility functions
β βββ logger.ts # Winston logger
β βββ embeds.ts # Embed templates
β βββ permissions.ts # Permission utilities
βββ types/ # TypeScript type definitions
β βββ command.ts # Command and event interfaces
βββ index.ts # Main entry point
The bot uses SQLite with the following tables:
name(TEXT PRIMARY KEY) - Command namehash(TEXT) - Command data hash for change detectioncommand_id(TEXT) - Discord API command IDcreated_at(DATETIME) - Creation timestampupdated_at(DATETIME) - Last update timestamp
guild_id(TEXT PRIMARY KEY) - Discord guild IDprefix(TEXT) - Custom command prefixwelcome_channel_id(TEXT) - Welcome message channellog_channel_id(TEXT) - Logging channelcreated_at(DATETIME) - Creation timestampupdated_at(DATETIME) - Last update timestamp
user_id(TEXT) - Discord user IDguild_id(TEXT) - Discord guild IDcommands_used(INTEGER) - Number of commands usedmessages_sent(INTEGER) - Number of messages sentlast_active(DATETIME) - Last activity timestampcreated_at(DATETIME) - Creation timestampupdated_at(DATETIME) - Last update timestamp
Commands are automatically loaded from the src/commands/ directory. Here's an example:
import { SlashCommandBuilder, ChatInputCommandInteraction, Client } from 'discord.js';
export const data = new SlashCommandBuilder()
.setName('example')
.setDescription('An example command')
.addStringOption(option =>
option
.setName('input')
.setDescription('Some input')
.setRequired(true)
);
export async function execute(client: Client, interaction: ChatInputCommandInteraction): Promise<void> {
const input = interaction.options.getString('input');
await interaction.reply(`You said: ${input}`);
}Events are automatically loaded from the src/events/ directory:
import { Client, Events } from 'discord.js';
export const event = {
name: Events.MessageCreate,
once: false,
async execute(client: Client, message: Message): Promise<void> {
// Handle message event
},
};| Variable | Description | Required |
|---|---|---|
TOKEN |
Discord bot token | Yes |
CLIENT_ID |
Discord application ID | Yes |
NODE_ENV |
Environment (development/production) | No |
LOG_LEVEL |
Logging level (error/warn/info/debug) | No |
The bot uses Winston for logging with the following levels:
error- Error messageswarn- Warning messagesinfo- General informationdebug- Debug information
Logs are saved to:
logs/error.log- Error logs onlylogs/combined.log- All logs
# Run tests
npm test
# Run tests with coverage
npm run test:coverage| Script | Description |
|---|---|
npm run dev |
Start in development mode |
npm run build |
Build TypeScript to JavaScript |
npm start |
Start production server |
npm run watch |
Start with file watching |
npm run lint |
Run ESLint |
npm run lint:fix |
Fix ESLint issues |
npm test |
Run tests |
npm run deploy |
Build and start production |
The bot includes a permission utility system:
import { PermissionUtils } from '../utils/permissions';
import { PermissionFlagsBits } from 'discord.js';
// Check permissions
const hasPermission = await PermissionUtils.requirePermissions(
interaction,
[PermissionFlagsBits.ManageGuild],
'You need Manage Server permission!'
);Pre-built embed templates for consistent UI:
import { EmbedUtils } from '../utils/embeds';
const embed = EmbedUtils.success('Success!', 'Operation completed successfully');
await interaction.reply({ embeds: [embed] });npm run devnpm run build
npm startFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY dist ./dist
CMD ["npm", "start"]- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
Built by OfficialAudite
Need help? Open an issue or check the Discord.js documentation.