Environment Variables
Rosy Music Bot uses environment variables to store sensitive credentials. These are loaded from the.env file using the dotenv package.
Creating Your .env File
Environment Variable Reference
| Variable | Required | Description | Example |
|---|---|---|---|
TOKEN | Yes | Discord bot token | MTA1M... |
YOUTUBE_API_KEY | Yes | YouTube Data API v3 key | AIzaSyC... |
SPOTIFY_CLIENT_ID | Yes | Spotify application client ID | a1b2c3d4... |
SPOTIFY_CLIENT_SECRET | Yes | Spotify application secret | x9y8z7w6... |
All four environment variables are required for the bot to function properly. Missing any will cause startup errors.
Bot Configuration (config.js)
Theconfig.js file contains bot behavior settings. This file is located in the root directory.
Current Configuration
config.js
Configuration Options
Command Prefix
Command Prefix
Current value: Customizing the prefix:
r!The prefix is the character(s) that must start every command.After changing the prefix, restart the bot for changes to take effect.
Bot Presence/Status
Bot Presence/Status
Current configuration:Activity Types:
LISTENING- “Listening to r!help”WATCHING- “Watching r!help para comandos”PLAYING- “Playing [name]”STREAMING- “Streaming [name]”COMPETING- “Competing in [name]”
online- Green circle 🟢idle- Orange/yellow moon 🌙dnd- Red circle (Do Not Disturb) 🔴invisible- Appears offline
The actual presence set in code (
index.js:46-49) overrides the config presence. To use config presence, modify the setPresence call in index.js.Modifying config.js
DisTube Configuration
DisTube is the music system that powers Rosy Music Bot. It’s configured inindex.js:24-36.
Current DisTube Setup
index.js
DisTube Configuration Options
emitNewSongOnly
emitNewSongOnly
Current value:
trueWhen true, the playSong event only fires when a new song starts, not when resuming.Recommended to keep as
true to avoid duplicate “Now Playing” messages.emitAddSongWhenCreatingQueue
emitAddSongWhenCreatingQueue
Current value:
falseWhen false, prevents emitting addSong event when the first song creates a new queue.Keep as
false to prevent redundant “Added to queue” messages for the first song.Additional Options (Optional)
Additional Options (Optional)
You can add more DisTube options:
Plugin Configuration
Spotify Plugin
Spotify Plugin
Current configuration:This plugin enables Spotify URL and playlist support.Additional options:
YtDlp Plugin
YtDlp Plugin
Current configuration:This plugin uses yt-dlp for YouTube downloads with automatic updates.Additional options:
Client Configuration
The Discord client is configured with specific intents inindex.js:10-17.
Required Intents
index.js
Optional Intents
You can add additional intents if needed:Some intents like
GuildMembers and MessageContent are privileged and must be enabled in the Discord Developer Portal.Starting the Bot
Once configuration is complete, start the bot:Verify Configuration
Check that:
.envfile exists with all four credentialsconfig.jshas your desired settings- Bot is invited to your Discord server
Check Discord
In Discord, verify:
- Bot shows as online with “idle” status 🌙
- Bot’s custom status shows “r!help 🎶”
Advanced Configuration
Custom Event Handlers
Custom Event Handlers
Event handlers are located in To customize events:
handlers/events directory and loaded in index.js:44:- Navigate to
handlers/events/ - Modify existing event files
- Restart the bot
Custom Commands
Custom Commands
Commands are located in To add or modify commands:
commands/ directory and loaded in index.js:43:- Navigate to
commands/directory - Create/edit command files
- Restart the bot
Command structure details are covered in the Commands documentation.
Custom Logger Configuration
Custom Logger Configuration
The bot uses a custom logger (Logger usage examples from the code:
utils/logger). It’s imported in index.js:7:Event Listener Limits
Event Listener Limits
The bot increases the default event listener limit in This prevents “MaxListenersExceededWarning” errors with multiple audio streams.If you see listener warnings:
index.js:8:Troubleshooting
Bot Won't Start
Bot Won't Start
Common causes:
- Missing or invalid environment variables
- Syntax errors in config.js
- Node.js version too old
- Check
.envfile exists and has all four variables - Verify no syntax errors in
config.js - Run
node --version(must be 18.17.0+) - Check console for specific error messages
Commands Don't Work
Commands Don't Work
Common causes:
- Wrong prefix in config.js
- Message Content intent not enabled
- Bot missing permissions
- Verify prefix in
config.jsmatches what you’re typing - Enable Message Content intent in Developer Portal
- Check bot has “Send Messages” permission
- Review console logs for command execution errors
Music Playback Fails
Music Playback Fails
Common causes:
- yt-dlp plugin not fixed
- Invalid API credentials
- FFmpeg issues
- Apply the critical yt-dlp fix (comment out
noCallHome: true) - Verify YouTube and Spotify credentials in
.env - Test FFmpeg:
ffmpeg -version - Check console for specific playback errors
Environment Variables Not Loading
Environment Variables Not Loading
Common causes:
.envfile in wrong location- File named incorrectly
- Syntax errors in
.env
- Ensure
.envis in root directory (same level asindex.js) - Check file is named exactly
.env(not.env.txt) - Verify no spaces around
=signs - Ensure no quotes around values
- Restart bot completely after changes
Production Considerations
Process Management
Process Management
Use a process manager like PM2 to keep the bot running:
Environment-Specific Configs
Environment-Specific Configs
Use different configs for development and production:Then run with:
Error Handling
Error Handling
Add global error handlers in
index.js:Next Steps
With configuration complete, your bot is ready to use! Explore:- Commands Documentation - Learn all available commands
- Features Guide - Discover bot capabilities
- Customization - Modify the bot for your needs
Remember to restart the bot (Ctrl+C then
npm start) after any configuration changes.