Skip to content

๐ŸŽต ddj (Discord DJ) - Professional Discord music bot with real-time web control. Manual track selection, smooth crossfading, tag-based filtering, queue management, and YouTube integration. Perfect for gaming sessions and live events.

Notifications You must be signed in to change notification settings

botBehavior/ddj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commit
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

ddj (Discord DJ) - Setup Guide

๐ŸŽต Live Music Control for Discord Sessions

A minimal Discord music bot with real-time web control, manual track selection, tag-based filtering, and smooth crossfading. Perfect for gaming sessions, streams, or any Discord community.

๐Ÿ“‹ Prerequisites

Required Software

โœ… Node.js 20+ - Download from nodejs.org
โœ… Python 3.6+ - Required for building native dependencies (sqlite3, sodium)
โœ… Discord Bot - Create at discord.com/developers/applications

System Dependencies

โœ… FFmpeg - Automatically installed via npm package (no manual setup needed)
โœ… yt-dlp - For YouTube audio downloads
โœ… Build Tools - build-essential on Linux, or Visual Studio Build Tools on Windows

Installation Commands

Ubuntu/Debian:

sudo apt update
sudo apt install python3 python3-pip build-essential

macOS:

# Python usually comes pre-installed
# Install build tools via Xcode Command Line Tools:
xcode-select --install

Windows:

๐Ÿš€ Quick Start

1. Clone and Install Dependencies

git clone <your-repo-url>
cd ddj

# Install bot dependencies (includes FFmpeg automatically)
cd bot
npm install

# Install web dependencies
cd ../web
npm install

# Return to project root
cd ..

2. Configure Bot Environment

Copy the example and fill in your details:

cd bot
cp env.example .env

Edit bot/.env:

DISCORD_TOKEN=your_bot_token_here
GUILD_ID=your_server_id_here
VOICE_CHANNEL_ID=your_voice_channel_id_here
MUSIC_DIR=/path/to/your/music/folder
PORT=5140
CROSSFADE_SECS=4
VOLUME=0.35

To get your Discord IDs:

  1. Enable Developer Mode in Discord (User Settings โ†’ Advanced โ†’ Developer Mode)
  2. Right-click your server โ†’ "Copy ID" (for GUILD_ID)
  3. Right-click your voice channel โ†’ "Copy ID" (for VOICE_CHANNEL_ID)

Environment Variables:

  • MUSIC_DIR: Path to your music folder (defaults to ../../music relative to bot directory if not set)
  • PORT: Web API port (default: 5140)
  • CROSSFADE_SECS: Crossfade duration in seconds (default: 4)
  • VOLUME: Default volume 0.0-1.0 (default: 0.35)

3. Add Music and Start Services

First, add some music to your MUSIC_DIR folder, then start the bot:

cd bot
npm start

You should see:

Seeding music database...
โœ… Logged in as YourBot#1234
REST API running on: http://localhost:5140/api
Music library: /path/to/your/music/folder

4. Start the Web UI

In a new terminal:

cd web
npm run dev

Open http://localhost:3000 in your browser to access the control panel.

๐ŸŽฎ How to Use

Initial Setup (One-time)

  1. Import Music: Bot automatically scans your MUSIC_DIR on startup
  2. Add Tags: Browse tracks in the web UI and add tags like:
    • tavern, combat, peaceful, tense
    • mysterious, epic, ambient, dramatic

Live Session Control

The web UI features three main tabs:

๐ŸŽต Music Library Tab

  • Filter by Tags: Click tag buttons to narrow track options
  • Browse Results: See all matching tracks with metadata and tags
  • Manual Selection: Click "Play โ–ถ" on any track for instant playback
  • YouTube Downloads: Paste YouTube URLs to download and add audio tracks
  • Track Management: Rename tracks, update metadata, or delete tracks

๐Ÿ“‹ Queue Tab

  • Queue Management: Add tracks to a playback queue
  • Reorder Queue: Drag and drop to rearrange track order
  • Skip Tracks: Skip to next track in queue
  • Clear Queue: Remove all queued tracks

โšก Quick Actions Tab

  • Playback Controls: Play, skip, stop, or force-stop current track
  • Volume Control: Adjust playback volume (0-100%)
  • Now Playing: See current track and volume status
  • Voice Connection: Manually disconnect bot from voice channel

Example Workflow

DM: "You enter a suspicious tavern..."
โ†’ Music Library tab โ†’ Filter: "tavern" + "tense"
โ†’ See 5 matching tracks with metadata visible
โ†’ Click "Play" on "Shady_Negotiations.mp3"
โ†’ Smooth 4-second crossfade begins
โ†’ Add "investigation" tag while playing for future sessions
โ†’ Queue next tracks for continuous music flow

๐Ÿ”ง Features

Core Functionality

  • Manual Control: You choose every track, no random auto-play
  • Tag-Based Filtering: Build your musical vocabulary over time
  • Smooth Crossfading: Professional transitions via FFmpeg (configurable duration)
  • Live Tagging: Add tags during sessions to enhance future discovery
  • Local-First: Your music, your tags, your control
  • Real-Time: Instant response to scene changes

Advanced Features

  • Queue Management: Add, reorder, and manage playback queues
  • YouTube Integration: Download audio directly from YouTube URLs
  • Metadata Support: Automatic extraction of title, artist, album from audio files
  • Custom Naming: Override default track names for better organization
  • Volume Control: Real-time volume adjustment (0-100%)
  • Force Stop: Emergency stop for all audio playback
  • Voice Connection Management: Manual connect/disconnect controls

Technical Features

  • SQLite Database: Persistent storage for tracks, tags, and metadata
  • REST API: Full programmatic access to all bot functions
  • Modern Web UI: Responsive interface built with Next.js + Tailwind CSS
  • Cross-Platform: Works on Windows, macOS, and Linux
  • FFmpeg Integration: High-quality audio processing with automatic installation

๐Ÿ›  Troubleshooting

Bot Issues

Bot won't start:

  • Check your Discord token is valid and has proper bot permissions
  • Ensure Python 3.6+ is installed (required for native dependencies)
  • Verify GUILD_ID and VOICE_CHANNEL_ID are correct (enable Developer Mode in Discord)
  • Check that build tools are installed for native module compilation

Voice connection fails:

  • Ensure bot has proper voice channel permissions in your Discord server
  • Check that the voice channel exists and bot can access it
  • Try manually disconnecting and reconnecting the bot

Audio playback issues:

  • Verify FFmpeg is working (automatically installed via npm)
  • Check audio file formats are supported (.mp3, .flac, .wav, .m4a, .ogg)
  • Ensure MUSIC_DIR path is correct and accessible

Web UI Issues

Web UI can't connect:

  • Ensure bot is running on port 5140 (check bot startup logs)
  • Verify no firewall is blocking localhost connections
  • Check browser console for network errors

UI not loading:

  • Ensure Node.js dependencies are installed (npm install in web directory)
  • Check that port 3000 is available
  • Try clearing browser cache and cookies

Database Issues

Music not importing:

  • Check MUSIC_DIR contains valid audio files
  • Ensure write permissions for database file creation
  • Try deleting catalog.db and restarting bot to re-import

Tags not saving:

  • Check database file permissions
  • Ensure bot has write access to its directory

YouTube Download Issues

Download fails:

  • Ensure yt-dlp is installed and in system PATH
  • Check YouTube URL is valid and accessible
  • Verify write permissions to MUSIC_DIR

๐Ÿ“ Project Structure

ddj/
โ”œโ”€โ”€ .gitignore              # Git ignore rules
โ”œโ”€โ”€ README.md               # This file
โ”œโ”€โ”€ bot/                    # Discord bot backend
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ index.js        # Main bot entry point & voice connection
โ”‚   โ”‚   โ”œโ”€โ”€ audioEngine.js  # FFmpeg crossfade engine & audio player
โ”‚   โ”‚   โ”œโ”€โ”€ catalog.js      # SQLite database & track management
โ”‚   โ”‚   โ””โ”€โ”€ routes.js       # REST API endpoints
โ”‚   โ”œโ”€โ”€ catalog.db          # SQLite database (auto-created)
โ”‚   โ”œโ”€โ”€ env.example         # Environment configuration template
โ”‚   โ”œโ”€โ”€ package.json        # Bot dependencies
โ”‚   โ””โ”€โ”€ package-lock.json   # Dependency lock file
โ””โ”€โ”€ web/                    # Next.js web interface
    โ”œโ”€โ”€ src/
    โ”‚   โ”œโ”€โ”€ app/
    โ”‚   โ”‚   โ”œโ”€โ”€ layout.tsx  # App layout
    โ”‚   โ”‚   โ”œโ”€โ”€ page.tsx    # Main page
    โ”‚   โ”‚   โ””โ”€โ”€ error.tsx   # Error page
    โ”‚   โ”œโ”€โ”€ components/
    โ”‚   โ”‚   โ”œโ”€โ”€ LiveDJPanel.tsx      # Main DJ panel
    โ”‚   โ”‚   โ”œโ”€โ”€ MusicCard.tsx        # Individual track component
    โ”‚   โ”‚   โ”œโ”€โ”€ TabbedMusicInterface.tsx # Tabbed interface
    โ”‚   โ”‚   โ””โ”€โ”€ tabs/
    โ”‚   โ”‚       โ”œโ”€โ”€ MusicLibraryTab.tsx  # Music library management
    โ”‚   โ”‚       โ”œโ”€โ”€ QueueTab.tsx         # Queue management
    โ”‚   โ”‚       โ””โ”€โ”€ QuickActionsTab.tsx  # Playback controls
    โ”‚   โ”‚   โ””โ”€โ”€ ui/              # Shadcn/ui components
    โ”‚   โ”‚       โ”œโ”€โ”€ button.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ card.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ dialog.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ dropdown-menu.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ input.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ progress.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ scroll-area.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ separator.tsx
    โ”‚   โ”‚       โ”œโ”€โ”€ slider.tsx
    โ”‚   โ”‚       โ””โ”€โ”€ badge.tsx
    โ”‚   โ”œโ”€โ”€ lib/
    โ”‚   โ”‚   โ”œโ”€โ”€ api.ts         # API client utilities
    โ”‚   โ”‚   โ””โ”€โ”€ utils.ts       # Utility functions
    โ”‚   โ””โ”€โ”€ styles/
    โ”‚       โ””โ”€โ”€ globals.css    # Global styles
    โ”œโ”€โ”€ components.json       # Shadcn/ui configuration
    โ”œโ”€โ”€ next.config.js        # Next.js configuration
    โ”œโ”€โ”€ package.json          # Web dependencies
    โ”œโ”€โ”€ package-lock.json     # Dependency lock file
    โ”œโ”€โ”€ postcss.config.js     # PostCSS configuration
    โ”œโ”€โ”€ tailwind.config.js    # Tailwind CSS configuration
    โ””โ”€โ”€ tsconfig.json         # TypeScript configuration

๐Ÿš€ Production Deployment

Environment Setup

For production use, you may want to:

  1. Change API_BASE in web UI:

    // In web/src/lib/api.ts
    const API_BASE = 'https://your-domain.com/api'; // For production
  2. Set up reverse proxy (nginx/apache) to serve both web UI and API from same domain

  3. Configure firewall to allow access to your chosen ports

  4. Use process manager like PM2 for production bot deployment:

    npm install -g pm2
    cd bot
    pm2 start src/index.js --name "ddj-bot"

API Reference

The bot provides a REST API on port 5140 (configurable):

  • GET /api/health - Health check
  • GET /api/tracks - List tracks with optional tag filtering
  • POST /api/play - Play specific track by ID
  • POST /api/next - Skip to next track
  • POST /api/stop / POST /api/force-stop - Stop playback
  • POST /api/volume - Set volume (0.0-1.0)
  • POST /api/tag/:id - Add tag to track
  • DELETE /api/tag/:id - Remove tag from track
  • DELETE /api/track/:id - Delete track
  • POST /api/youtube/download - Download from YouTube URL
  • GET/POST /api/queue/* - Queue management endpoints

๐ŸŽต Growing Your Musical Vocabulary

Start simple and build over time:

Session 1: tavern, combat, peaceful, tense
Session 5: Add mysterious, epic, dramatic, chase, victory
Session 20: 50+ precise tags for perfect atmospheric control

The system becomes more powerful with every session as your tagging vocabulary expands!


Ready to DJ your next Discord session? ๐ŸŽต๐Ÿค–

About

๐ŸŽต ddj (Discord DJ) - Professional Discord music bot with real-time web control. Manual track selection, smooth crossfading, tag-based filtering, queue management, and YouTube integration. Perfect for gaming sessions and live events.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published