Overview
The bot needs three API credentials configured in your.env file:
All API credentials are free for personal use and moderate traffic. You won’t need to provide payment information unless you exceed generous free tier limits.
YouTube API Key
The YouTube Data API v3 allows the bot to search for and retrieve YouTube videos.Access Google Cloud Console
Navigate to Google Cloud Console and sign in with your Google account.
Create a New Project
- Click the project dropdown at the top of the page (next to “Google Cloud”)
- Click “New Project”
- Enter a project name (e.g., “Rosy Music Bot”)
- Click “Create”
- Wait for the project to be created, then select it
If you already have a Google Cloud project you want to use, you can skip this step and select that project instead.
Enable YouTube Data API v3
- In the left sidebar, go to “APIs & Services” → “Library”
- Search for “YouTube Data API v3”
- Click on “YouTube Data API v3” from the results
- Click the “Enable” button
- Wait for the API to be enabled
Create API Credentials
- Go to “APIs & Services” → “Credentials”
- Click “Create Credentials” at the top
- Select “API Key”
- Your API key will be generated and displayed
- Click “Copy” to copy the key to your clipboard
Restrict API Key (Recommended)
For better security, restrict your API key:
- Click “Edit API key” (or find your key in the credentials list)
- Under “API restrictions”, select “Restrict key”
- Choose “YouTube Data API v3” from the dropdown
- Click “Save”
YouTube API Quota Limits
The YouTube Data API v3 has a free daily quota of 10,000 units. Here’s what this means:- Search: ~100 units per query
- Video details: ~1 unit per video
What if I exceed the quota?
What if I exceed the quota?
If you exceed the quota:
- The bot will return errors when trying to play YouTube videos
- The quota resets at midnight Pacific Time (PT)
- For high-traffic bots, you can request a quota increase from Google
- Consider using Spotify or direct URLs as alternatives
Spotify API Credentials
Spotify credentials allow the bot to play Spotify tracks and playlists. The bot uses the@distube/spotify plugin configured in index.js:28-33.
Access Spotify Developer Dashboard
Navigate to Spotify Developer Dashboard and log in with your Spotify account.
You don’t need Spotify Premium. A free Spotify account is sufficient for API access.
Create an App
- Click “Create app” button
- Fill in the app information:
- App name: “Rosy Music Bot” (or any name)
- App description: “Discord music bot for playing Spotify tracks”
- Redirect URI:
http://localhost:3000(required but not used)
- Check the checkbox to agree to Spotify’s Terms of Service
- Click “Save”
Get Client ID
After creating the app:
- You’ll be taken to your app’s dashboard
- Your Client ID is displayed prominently
- Click “Copy” or manually copy the Client ID
Get Client Secret
- On the same page, click “Show Client Secret”
- Your Client Secret will be revealed
- Click “Copy” or manually copy the Client Secret
How Spotify Integration Works
The bot integrates Spotify using the DisTube Spotify plugin:This configuration is found in
index.js:28-33. The plugin handles Spotify authentication automatically using your credentials.Spotify API Limits
Spotify’s free tier is generous:- Rate limit: Rarely an issue for music bots
- No daily quota: Unlike YouTube, Spotify doesn’t have daily quotas
- Extended Rate Limit Mode: Automatically applied if limits are exceeded (very rare)
Security Best Practices
Storing Credentials Securely
-
Use Environment Variables
- Store all credentials in
.envfile - Never hardcode them in source code
- The bot uses
dotenvpackage to load them (seeindex.js:1)
- Store all credentials in
-
Add .env to .gitignore
-
Use .env.example as Template
The repository includes
.env.exampleas a template:Copy this file and fill in your real credentials:
What NOT to Do
- Don’t commit .env to Git: Always keep it in .gitignore
- Don’t share in Discord/chat: Never paste credentials in messages
- Don’t include in screenshots: Be careful when sharing screenshots
- Don’t use in client-side code: These are server-side credentials only
- Don’t share your .env file: Each deployment should have its own credentials
Rotating Compromised Keys
If you accidentally expose credentials:YouTube API Key
YouTube API Key
- Go to Google Cloud Console
- Navigate to APIs & Services → Credentials
- Find your API key and click the delete icon
- Create a new API key following the steps above
- Update your
.envfile with the new key - Restart the bot
Spotify Credentials
Spotify Credentials
- Go to Spotify Developer Dashboard
- Open your app
- Click “Show Client Secret”
- Click “Rotate Client Secret”
- Copy the new secret
- Update your
.envfile with the new secret - Restart the bot
The Client ID doesn’t change when rotating the secret.
Verifying API Setup
After obtaining all credentials, verify they’re configured correctly:Check File Format
Verify your
.env file:- No empty lines between variables
- No comments (lines starting with #)
- No quotes around values
- No spaces around
=
Troubleshooting
YouTube API Errors
YouTube API Errors
Error: “Invalid API key”
- Verify the key is copied correctly in
.env - Check there are no extra spaces or quotes
- Ensure YouTube Data API v3 is enabled in Google Cloud Console
- You’ve hit the daily limit of 10,000 units
- Wait until midnight PT for quota reset
- Consider requesting quota increase from Google
- Use Spotify or direct URLs temporarily
- Ensure
.envfile exists in root directory - Verify
YOUTUBE_API_KEYis spelled correctly - Restart the bot after updating
.env
Spotify API Errors
Spotify API Errors
Error: “Invalid client”
- Verify Client ID and Secret are correct
- Check for typos in
.env - Ensure no extra spaces or quotes around values
- Client Secret may have been rotated
- Generate new credentials from Spotify Dashboard
- Update
.envwith new credentials
- Verify both Client ID and Secret are set
- Check the bot console for specific error messages
- Ensure
@distube/spotifypackage is installed
.env File Not Loading
.env File Not Loading
Credentials not being read:
- Verify
.envis in the root directory (same level asindex.js) - Check file is named exactly
.env(not.env.txt) - Ensure
dotenvpackage is installed:npm install dotenv - Verify
require('dotenv').config();is at the top ofindex.js:1 - Restart the bot completely (Ctrl+C and
npm startagain)
- Ensure you can see file extensions
- File might be saved as
.env.txtby default - Rename to
.envwithout any extension
Next Steps
With all API credentials obtained and saved, proceed to: Configuration - Configure bot settings and start using Rosy Music BotKeep your
.env file secure and backed up safely. These credentials are required every time you run the bot.