Directory Overview
Core Files
index.js
The main entry point that bootstraps the bot:- Initializes Discord.js client with required intents
- Sets up DisTube with Spotify and YtDlp plugins
- Loads command and event handlers
- Implements message command parsing
- Sets bot presence and activity status
index.js:40-50
config.js
Centralized configuration for bot settings:- Command prefix (
r!) - Bot presence configuration
- Activity types and status
config.js:1-10
Commands Directory
/commands/music/
Contains all music-related command implementations. Each file exports a command module.Command Module Structure
Available Commands
play.js
Searches and plays songs from YouTube or Spotify URLs. Implements:
- Voice channel validation
- Permission checks
- YouTube search with play-dl
- Interactive song selection menu
- Queue management
pause.js
Pauses the current song playback.
resume.js
Resumes paused playback.
skip.js
Skips to the next song in the queue.
stop.js
Stops playback and clears the queue.
volume.js
Adjusts playback volume (0-100%).
queue.js
Displays the current song queue with durations.
status.js
Shows bot status and current playback information.
help.js
Lists all available commands with usage examples.
Example: play.js Structure
commands/music/play.js:6-9
- Validates user is in voice channel
- Checks bot permissions (Connect, Speak)
- Searches YouTube using play-dl library
- Displays interactive selection menu for multiple results
- Handles URL and search query formats
Events Directory
/events/client/
Handles Discord client events.interactionCreate.js
Processes button interactions for music controls:events/client/interactionCreate.js:4-18
music_pause,music_resume,music_skip,music_stop,music_loopvolume_up,volume_down,volume_mute
messageCreate.js
Note: Message handling is primarily done inindex.js (index.js:52-68). This event file is excluded from the handler to avoid duplication.
/events/distube/
Handles DisTube music playback events.playSong.js
Triggered when a new song starts playing:- Creates “Now Playing” embed with song info
- Adds music control buttons
- Starts real-time progress updater
- Logs playback information
error.js
Handles DisTube errors and displays user-friendly error messages.debug.js
Logs DisTube debug information for troubleshooting.setup.js
Initial DisTube configuration:events/distube/setup.js:1-4
- Increases max listeners to prevent warnings
- Handles voice connection state changes
- Manages disconnect events
- Implements auto-resume on connection issues
Handlers Directory
handlers/commands.js
Dynamically loads all command files:handlers/commands.js:4-23
- Reads all folders in
/commands/ - Finds all
.jsfiles in each folder - Requires each command file
- Registers command in
client.commandsCollection
handlers/events.js
Dynamically loads client and DisTube events:handlers/events.js:5-18
/events/client/(excludes messageCreate.js to avoid duplication)/events/distube/
Utils Directory
utils/embeds.js
Factory functions for creating Discord embeds: Exports:createNowPlayingEmbed(song, queue)- Current song with progress barcreateAddedToQueueEmbed(song, position)- Song added confirmationcreateQueueEmbed(queue)- Full queue listingcreateErrorEmbed(title, description)- Error messagescreateInfoEmbed(title, description)- Information messagescreateProgressBar(current, total, length)- Visual progress barformatDuration(seconds)- Time formatting (HH:MM:SS)
utils/embeds.js:3-10
utils/logger.js
Structured logging system with multiple log levels: Methods:Logger.music(message, location)- Music playback logsLogger.distube(message, location)- DisTube engine logsLogger.voice(message, location)- Voice connection logsLogger.error(message, error, location)- Error logs with stack tracesLogger.warn(message, location)- Warning logsLogger.success(message, location)- Success logsLogger.info(message, location)- Info logsLogger.command(commandName, user, guild)- Command execution logs
utils/logger.js:7-10
utils/musicControls.js
Interactive button components and handlers: Exports:createMusicButtons()- Returns ActionRow with pause, resume, skip, stop, loop buttonscreateVolumeButtons()- Returns ActionRow with volume +/-, mute buttonshandleMusicButton(interaction, client)- Processes button interactions
utils/musicControls.js:4-30
- Validates queue exists
- Checks user is in voice channel
- Verifies user is in same voice channel as bot
- Executes appropriate queue action
- Sends ephemeral confirmation message
utils/progressUpdater.js
Real-time embed update system: Exports:startProgressUpdater(message, queue, song)- Starts 10-second update intervalstopProgressUpdater(queueId)- Stops updater for specific queuestopAllUpdaters()- Cleanup function for all active updaters
utils/progressUpdater.js:7-33
File Naming Conventions
Command Files
Command Files
Pattern:
commandname.js (lowercase, single word)Examples:play.js- Play commandskip.js- Skip commandvolume.js- Volume command
name, description, and execute properties.Event Files
Event Files
Pattern:
eventName.js (camelCase, matches Discord.js event name)Examples:interactionCreate.js- Maps to ‘interactionCreate’ eventplaySong.js- Maps to ‘playSong’ DisTube eventmessageCreate.js- Maps to ‘messageCreate’ event
Utility Files
Utility Files
Pattern:
moduleName.js (camelCase, descriptive)Examples:embeds.js- Embed creation utilitieslogger.js- Logging systemmusicControls.js- Music control buttons and handlersprogressUpdater.js- Progress update system
Handler Files
Handler Files
Pattern:
type.js (lowercase, singular)Examples:commands.js- Command loaderevents.js- Event loader
Adding New Files
Adding a New Command
- Create file in
/commands/music/yourcommand.js - Use the command template:
- The command will be automatically loaded on bot restart
Adding a New Event
- Create file in
/events/client/or/events/distube/ - Export a function that registers the event:
- The event will be automatically registered on bot startup
Adding a New Utility
- Create file in
/utils/yourutil.js - Export functions or classes:
- Import in files that need it: