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-template
npm install
Create 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 watch
src/
├── 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 dev
npm run build
npm start
FROM 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.