Skip to main content

Discord Bot Integration

The ErikrafT Drop Discord bot brings file sharing capabilities directly to Discord servers, enabling users to send and receive files through Discord commands while maintaining the security and efficiency of the ErikrafT Drop peer-to-peer system.

Bot Overview

Core Functionality

The Discord bot provides a bridge between Discord and ErikrafT Drop:
  • Slash Commands: /drop command for file sharing operations
  • Real-time Integration: Appears as paired device in ErikrafT Drop web interface
  • Multi-file Support: Send up to 3 files per command
  • Text Messaging: Send text messages alongside files
  • Bidirectional Transfer: Send and receive files through Discord

Technical Architecture

Installation and Setup

Bot Invitation

Invite the bot to your Discord server: https://discord.com/oauth2/authorize?client_id=1367869058707492955

Prerequisites

  • Node.js 18+: Required for bot operation
  • Discord Server: Server with bot administration permissions
  • ErikrafT Drop Instance: With WebSocket fallback enabled
  • Bot Application: Registered on Discord Developer Portal

Self-Hosting Setup

1. Discord Application Setup

  1. Create Application: Visit Discord Developer Portal
  2. Create Bot: Add bot to application
  3. Configure Permissions: Set appropriate bot permissions
  4. Generate Token: Create bot token for authentication

2. Bot Configuration

3. Environment Variables

Configure .env file with required variables:

4. Command Registration

Bot Architecture

Project Structure

Core Components

Main Bot Instance (src/index.js)

ErikrafT Drop Client (src/client/dropClient.js)

Drop Command (src/commands/drop.js)

Command Usage

/drop Command

The primary command for file sharing operations:

Command Options

Usage Examples

Basic File Sharing:
With Custom Name:
Text Message Only:
Multiple Files:

Command Features

File Handling

  • Multiple Files: Support for up to 3 files per command
  • File Types: All file types supported
  • Size Limits: Respects Discord file size limits
  • Processing: Files processed in memory without disk storage

Message Handling

  • Text Messages: Send text messages up to 2000 characters
  • Formatting: Supports Discord markdown formatting
  • Encoding: Proper character encoding for international text
  • Validation: Input validation and sanitization

Response Handling

  • Ephemeral Messages: Responses visible only to command user
  • Progress Feedback: Real-time transfer progress updates
  • Error Handling: Graceful error handling and user feedback
  • Completion Notification: Transfer completion confirmation

Integration Features

Real-time Device Discovery

The bot appears as a paired device in the ErikrafT Drop web interface:

Device Identification

Connection Status

  • Online Indicator: Shows when bot is connected
  • Real-time Updates: Connection status updates in real-time
  • Auto-reconnection: Automatic reconnection on disconnect
  • Error Reporting: Connection error notifications

WebSocket Fallback Integration

The bot uses WebSocket fallback for file transfers:

Transfer Process

Data Handling

  • Base64 Encoding: Files encoded as base64 for WebSocket transfer
  • Chunking: Large files chunked for efficient transfer
  • Memory Management: Files processed in memory without disk storage
  • Error Recovery: Automatic retry on transfer failures

Security Features

Authentication and Authorization

Discord Authentication

  • Bot Token: Secure Discord bot token authentication
  • Guild Permissions: Server-specific permission validation
  • Command Permissions: Role-based command access control
  • User Validation: Discord user identity verification

ErikrafT Drop Integration

  • Pairing Key Validation: 6-digit key format validation
  • Room Access: Secure room access through pairing keys
  • Connection Authentication: WebSocket connection authentication
  • Transfer Authorization: Transfer request authorization

Data Protection

Privacy Measures

  • No Disk Storage: Files never written to disk
  • Memory Processing: All processing in memory only
  • Ephemeral Messages: Discord responses are ephemeral
  • Secure Transmission: Encrypted WebSocket transmission

Security Best Practices

  • Token Security: Secure token storage and handling
  • Input Validation: Comprehensive input validation and sanitization
  • Rate Limiting: Command rate limiting to prevent abuse
  • Error Handling: Secure error handling without information leakage

Performance Optimization

Memory Management

  • Efficient Processing: Optimized file processing algorithms
  • Memory Cleanup: Automatic memory cleanup after transfers
  • Stream Processing: Stream-based file processing for large files
  • Garbage Collection: Proper garbage collection practices

Network Optimization

  • Connection Pooling: Efficient WebSocket connection management
  • Compression: Data compression for improved transfer speed
  • Timeout Management: Appropriate timeout settings
  • Retry Logic: Intelligent retry mechanisms

Bot Performance

  • Asynchronous Operations: Non-blocking file processing
  • Concurrent Handling: Handle multiple concurrent transfers
  • Resource Management: Efficient resource utilization
  • Scalability: Designed for multiple server support

Deployment Options

Self-Hosting

Deploy the bot on your own infrastructure:

Local Deployment

Production Deployment

Docker Deployment

Cloud Hosting

Deploy to cloud platforms for 24/7 operation:

Configuration Examples

Troubleshooting

Common Issues

Connection Problems

  • WebSocket Connection: Verify ErikrafT Drop server accessibility
  • Discord API: Check Discord API status and bot permissions
  • Network Issues: Verify network connectivity and firewall settings
  • Token Issues: Validate Discord bot token and application ID

Command Issues

  • Command Registration: Ensure slash commands are properly registered
  • Permissions: Verify bot has necessary permissions in server
  • Key Validation: Check pairing key format and validity
  • File Processing: Verify file size and type constraints

Transfer Issues

  • File Size: Check Discord file size limitations
  • Memory Issues: Monitor bot memory usage
  • Network Stability: Verify network stability during transfers
  • Server Status: Check ErikrafT Drop server status

Debug Information

Bot Diagnostics

WebSocket Diagnostics

Future Development

Planned Enhancements

Feature Improvements

  • Additional Commands: More Discord slash commands
  • File Type Support: Enhanced file type handling
  • Progress Indicators: Better progress indication
  • Error Handling: Improved error handling and user feedback

Integration Enhancements

  • Multi-server Support: Support for multiple Discord servers
  • Role-based Access: Advanced role-based permissions
  • Custom Commands: Custom command configuration
  • Webhook Integration: Discord webhook integration

Performance Improvements

  • Caching: Implement intelligent caching mechanisms
  • Load Balancing: Support for load balancing
  • Monitoring: Enhanced monitoring and alerting
  • Scalability: Improved scalability for large servers
The Discord bot integration provides a powerful bridge between Discord communities and the ErikrafT Drop ecosystem, enabling seamless file sharing within Discord servers while maintaining the security and efficiency of the peer-to-peer file transfer system.