A modern, feature-rich Discord bot handler built with Discord.js v14, featuring both slash commands and prefix commands with a robust architecture designed for scalability and maintainability.
- Dual Command System: Support for both slash commands and prefix commands
- Modular Architecture: Clean separation of concerns with dedicated handlers
- Anti-Crash System: Comprehensive error handling and monitoring
- Event-Driven: Fully event-driven architecture
- ES6 Modules: Modern JavaScript with ES6 module syntax
- Environment Configuration: Secure configuration management with dotenv
bot_handler/
βββ package.json # Project dependencies and scripts
βββ README.md # Project documentation
βββ Core/ # Core utilities and webhooks
β βββ commandUtils.js # Utilities for handling commands
β βββ emojis.js # Centralized emoji definitions
β βββ errorWebhook.js # Error reporting via webhook
β βββ joinGuildWebhook.js # Webhook when the bot joins a guild
β βββ leaveGuildWebhook.js # Webhook when the bot leaves a guild
β βββ prefixCommandWebhook.js # Webhook logging for prefix commands
β βββ readyWebhook.js # Webhook logging for bot ready event
β βββ slashCommandWebhook.js # Webhook logging for slash commands
β
βββ Database/
β βββ mongo.js # MongoDB connection setup
β
βββ Events/ # Discord event handlers
β βββ error.js # Global error event handler
β βββ guildCreate.js # Handler when bot joins a server
β βββ guildDelete.js # Handler when bot leaves a server
β βββ interactionCreate.js # Handles slash command interactions
β βββ messageCreate.js # Handles prefix commands
β βββ ready.js # Bot ready event
β
βββ Handlers/ # Handlers for modularity
β βββ AntiCrash.js # Crash prevention and error handling
β βββ Commands.js # Slash command loader/registration
β βββ Events.js # Event handler loader
β βββ logger.js # Logger for bot activity
β βββ Models.js # Models loader
β βββ Prefix.js # Prefix command loader
β
βββ Models/
β βββ userModel.js # Mongoose schema for user data
β βββ config.js # Bot configuration model
β
βββ Commands/
β βββ Prefix/ # Prefix commands
β β βββ Public/
β β βββ ping.js # Example prefix ping command
β βββ Slash/ # Slash commands
β βββ Public/
β βββ ping.js # Example slash ping command
β
βββ index.js # Main bot entry point
-
Clone the repository
git clone https://github.com/mrvirusdev/VirusDiscordHandler.git cd NewDiscordHandler -
Install dependencies
npm install
-
Environment Setup Open
config.jsonfile in the root directory with the following variables:# Discord Bot Configuration token = "Your Bot Token", clientId = "Your Bot Id", prefix = "Your Prefix", ownerIds = ["Owner Id 1", "Owner Id 2"], MONGODB_URI = "Your Mongo URL", errorWebhook = "Your Error Webhook", slashCommandWebhook = "Your SlashCommandLog Webhook", prefixCommandWebhook = "Your PrefixCommandLog Webhook", joinGuildWebhook = "Your BotJoinGulidLog Webhook", leaveGuildWebhook = "Your BotLeaveGulidLog Webhook", readyWebhook = "Your ReadyLog Webhook",TOKEN (Required):
- Go to Discord Developer Portal
- Create a new application or select existing one
- Go to "Bot" section
- Click "Reset Token" to get your bot token
CLIENT_ID (Required):
- In Discord Developer Portal, go to "General Information"
- Copy the "Application ID"
OWNER_IDS (Required):
- Enable Developer Mode in Discord settings
- Right-click your username and select "Copy ID"
- Use comma-separated values for multiple owners
ERROR_WEBHOOK_URL (Optional but Recommended):
- Create a Discord webhook in your server
- Go to Server Settings β Integrations β Webhooks
- Create a new webhook and copy the URL
β οΈ Security Note: Never commit yourconfig.jsonfile to version control! -
Run the bot
# For normal operation npm start
- discord.js: ^14.11.0 - Discord API wrapper
- @discordjs/rest: ^2.5.1 - REST API client
- discord-api-types: ^0.38.14 - TypeScript definitions
- dotenv: ^16.3.1 - Environment variable management
- axios: ^1.10.0 - HTTP client for webhooks
- node-fetch: ^3.3.2 - Fetch API for Node.js
- Initializes the Discord client with all intents and partials
- Loads all handlers in sequence
- Handles bot authentication
Slash Commands (Handlers/Commands.js)
- Automatically discovers and loads slash commands from the
Commands/Slash/directory - Registers commands with Discord's API
- Organizes commands by categories (folders)
Prefix Commands (Handlers/Prefix.js)
- Loads prefix commands from
Commands/Prefix/directory - Supports command aliases
- Uses
$as the default prefix
- Dynamically loads all event files from the
Events/directory - Supports both
onceandonevent listeners - Automatically passes client instance to event handlers
- Monitors for unhandled rejections and exceptions
- Sends error reports to Discord webhook
- Provides detailed error logging with timestamps
- Includes error type classification and status tracking
- Sets bot presence and status
- Confirms successful bot login
- Configurable activity display
- Processes slash command interactions
- Includes error handling with user-friendly messages
- Supports ephemeral responses
- Processes prefix commands
- Validates bot permissions
- Owner-only command support
- Automatic message cleanup for invalid usage
Create new slash commands in Commands/Slash/[category]/[command].js:
import { SlashCommandBuilder } from 'discord.js';
export default {
data: new SlashCommandBuilder()
.setName('commandname')
.setDescription('Command description'),
async execute(interaction) {
// Command logic here
await interaction.reply('Response');
}
};Create new prefix commands in Commands/Prefix/[category]/[command].js:
export default {
name: 'commandname',
description: 'Command description',
aliases: ['alias1', 'alias2'], // Optional
execute(client, message, args) {
// Command logic here
message.reply('Response');
}
};- Environment Variables: Sensitive data stored in
config.jsonfile - Permission Validation: Bot checks for required permissions
- Owner Verification: Support for multiple bot owners
- Error Isolation: Comprehensive error handling prevents crashes
- Console Logging: Color-coded system messages
- Error Webhooks: Real-time error reporting to Discord
- Client Health Checks: Periodic status monitoring
- Presence: Modify bot status in
Ready.js - Permissions: Adjust required permissions in event handlers
- Logging: Customize log formats and colors
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull
- π Detect and resolve all errors.
- β
Added automatic MongoDB connection using
MONGO_URI - π οΈ Collections are created automatically if not found
- π« Improved error handling for missing or invalid DB connections
Stay updated with the latest Discord.js features and security patches by regularly updating dependencies:
npm updateIf you need help setting up or using the bot, feel free to reach out:
- π© Communication via email: [email protected]
- π§ Contact the developer: 8yy2
ViruBot Discord Handler - A modern, scalable Discord bot framework built for the future.