Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

VirusBot Discord Handler

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.

πŸš€ Features

  • 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

πŸ“ Project Structure

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

πŸ”§ Installation

  1. Clone the repository

    git clone https://github.com/mrvirusdev/VirusDiscordHandler.git
    cd NewDiscordHandler
  2. Install dependencies

    npm install
  3. Environment Setup Open config.json file 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",
    

    How to Get These Values

    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 your config.json file to version control!

  4. Run the bot

    # For normal operation
    npm start

πŸ“‹ Dependencies

  • 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

πŸ—οΈ Architecture Overview

Core Components

1. Main Bot Entry (index.js)

  • Initializes the Discord client with all intents and partials
  • Loads all handlers in sequence
  • Handles bot authentication

2. Command Handlers

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

3. Event Handler (Handlers/Events.js)

  • Dynamically loads all event files from the Events/ directory
  • Supports both once and on event listeners
  • Automatically passes client instance to event handlers

4. Anti-Crash System (Handlers/AntiCrash.js)

  • 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

Event System

Ready Event (Events/Ready.js)

  • Sets bot presence and status
  • Confirms successful bot login
  • Configurable activity display

Interaction Handler (Events/interactionCreate.js)

  • Processes slash command interactions
  • Includes error handling with user-friendly messages
  • Supports ephemeral responses

Message Handler (Events/messageCreate.js)

  • Processes prefix commands
  • Validates bot permissions
  • Owner-only command support
  • Automatic message cleanup for invalid usage

πŸ“ Command Development

Creating Slash Commands

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');
  }
};

Creating Prefix Commands

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');
  }
};

πŸ”’ Security Features

  • Environment Variables: Sensitive data stored in config.json file
  • Permission Validation: Bot checks for required permissions
  • Owner Verification: Support for multiple bot owners
  • Error Isolation: Comprehensive error handling prevents crashes

πŸ“Š Monitoring and Logging

  • Console Logging: Color-coded system messages
  • Error Webhooks: Real-time error reporting to Discord
  • Client Health Checks: Periodic status monitoring

πŸ› οΈ Customization

Configuration Options

  • Presence: Modify bot status in Ready.js
  • Permissions: Adjust required permissions in event handlers
  • Logging: Customize log formats and colors

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull

πŸ“¦ Update v1.1.0

  1. 😁 Detect and resolve all errors.
  2. βœ… Added automatic MongoDB connection using MONGO_URI
  3. πŸ› οΈ Collections are created automatically if not found
  4. 🚫 Improved error handling for missing or invalid DB connections

πŸ”„ Updates

Stay updated with the latest Discord.js features and security patches by regularly updating dependencies:

npm update

πŸ†˜ Support

If you need help setting up or using the bot, feel free to reach out:


ViruBot Discord Handler - A modern, scalable Discord bot framework built for the future.

About

No description, website, or topics provided.

Resources

Stars

15 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages