discord-advanced-framework
v0.2.2
Published
Advanced, production-ready framework for Discord bots with TypeScript, IoC container, modular architecture, and hexagonal design
Maintainers
Readme
Discord Advanced Framework (DAF)
🚀 Production-ready Discord bot framework with TypeScript, Dependency Injection, and modern architecture patterns.
✨ Features
Core Features
- 🎯 Decorator-based - Clean, declarative syntax with
@Command,@OnEvent,@Cron - 💉 Dependency Injection - Built-in IoC container for modular architecture
- 🏗️ Modular Design - Organize code into modules with
@Module - 🔒 Guards & Middleware - Request pipeline with
@UseGuard,@UseMiddleware - 🌍 Internationalization - Multi-language support with
I18nManager - ⏰ Scheduled Tasks - Cron jobs with
@Crondecorator - 🎨 Utility Helpers - EmbedBuilder, Paginator, and more
Advanced Features
- 🔘 Button/Select Handlers -
@OnButton,@OnSelectMenudecorators - 💾 Database Adapters - Prisma, TypeORM, Drizzle support
- 🗄️ Cache Adapters - Redis, in-memory caching
- 🔥 Hot Reload - Development mode with auto-restart
- 📝 Message Commands - Legacy prefix-based commands
- 🧪 Fully Tested - Comprehensive test suite with Jest
📦 Installation
npm install discord-advanced-framework discord.jsQuick Start with CLI
npx discord-advanced-framework create my-bot
cd my-bot
npm install
npm run dev🚀 Quick Start
1. Create a Simple Bot
import { initializeFramework, SlashCommand, ExecutionContext, Service } from 'discord-advanced-framework';
import { Client, GatewayIntentBits } from 'discord.js';
// Define a command
@Service()
class PingCommand extends SlashCommand {
constructor() {
super({
name: 'ping',
description: 'Replies with Pong!',
});
}
async execute(context: ExecutionContext) {
await context.interaction.reply('🏓 Pong!');
}
}
// Initialize framework
const client = new Client({
intents: [GatewayIntentBits.Guilds],
});
initializeFramework(client, {
token: process.env.DISCORD_TOKEN!,
modules: [PingCommand],
});2. Using Modules
import { Module } from 'discord-advanced-framework';
@Module({
name: 'FunModule',
providers: [
PingCommand,
JokeCommand,
MemeCommand,
],
})
export class FunModule {}3. Dependency Injection
@Service()
class DatabaseService {
async getUser(id: string) {
// Database logic
}
}
@Service()
class UserCommand extends SlashCommand {
constructor(private db: DatabaseService) {
super({ name: 'user', description: 'Get user info' });
}
async execute(context: ExecutionContext) {
const user = await this.db.getUser(context.userId);
await context.interaction.reply(`User: ${user.name}`);
}
}📚 Documentation
Guides
- Commands - Slash commands, options, autocomplete
- Events - Discord event handling
- Dependency Injection - IoC container usage
- Guards & Middleware - Request pipeline
- Internationalization - Multi-language support
- Scheduled Tasks - Cron jobs
- Button & Select Handlers - Interactive components
- Pagination - Auto-pagination helper
- Database - ORM adapters
- Caching - Redis and in-memory cache
API Reference
🎯 Examples
Button Interaction
@Service()
class InteractiveCommand extends SlashCommand {
constructor() {
super({ name: 'interactive', description: 'Interactive buttons' });
}
async execute(context: ExecutionContext) {
const button = new ButtonBuilder()
.setCustomId('click_me')
.setLabel('Click Me!')
.setStyle(ButtonStyle.Primary);
await context.interaction.reply({
content: 'Click the button!',
components: [new ActionRowBuilder().addComponents(button)],
});
}
@OnButton('click_me')
async handleClick(interaction: ButtonInteraction) {
await interaction.reply({ content: '✅ Clicked!', flags: 64 });
}
}Scheduled Task
@Service()
class ScheduledTasks {
@Cron('0 0 * * *') // Daily at midnight
async dailyCleanup() {
console.log('Running daily cleanup...');
}
@Cron('*/5 * * * *') // Every 5 minutes
async statusCheck() {
console.log('Checking status...');
}
}Embed Builder
const embed = EmbedBuilder.success('Operation completed!')
.addField('User', 'John Doe')
.addField('Action', 'Updated profile')
.setTimestamp()
.build();
await interaction.reply({ embeds: [embed] });Pagination
const items = Array.from({ length: 50 }, (_, i) => `Item ${i + 1}`);
await Paginator.paginate(interaction, items, {
pageSize: 10,
renderer: (item) => `• ${item}`,
embedBuilder: (page, totalPages) =>
new EmbedBuilder().setTitle(`Items (Page ${page}/${totalPages})`),
});🛠️ Development
# Install dependencies
npm install
# Build framework
npm run build
# Run tests
npm test
# Watch mode
npm run watch📄 License
MIT © [Your Name]
🤝 Contributing
Contributions are welcome! Please read our Contributing Guide for details.
🔗 Links
Made with ❤️ for the Discord bot community
