https://github.com/mcbabel/discord-music-bot
๐ถ A powerful, feature-rich Discord Music Bot built with Node.js and discord.js v14. Seamless YouTube and Spotify integration with yt-dlp, Genius lyrics, custom playlists, and multi-language support (EN/DE/ES).
https://github.com/mcbabel/discord-music-bot
discord-api discord-bot discord-js discord-music-bot ffmpeg github-actions i18n javascript lyrics music-bot nodejs open-source spotify youtube yt-dlp
Last synced: 3 months ago
JSON representation
๐ถ A powerful, feature-rich Discord Music Bot built with Node.js and discord.js v14. Seamless YouTube and Spotify integration with yt-dlp, Genius lyrics, custom playlists, and multi-language support (EN/DE/ES).
- Host: GitHub
- URL: https://github.com/mcbabel/discord-music-bot
- Owner: MCbabel
- License: gpl-2.0
- Created: 2024-06-10T23:01:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2026-03-22T13:39:35.000Z (4 months ago)
- Last Synced: 2026-04-04T11:00:02.920Z (3 months ago)
- Topics: discord-api, discord-bot, discord-js, discord-music-bot, ffmpeg, github-actions, i18n, javascript, lyrics, music-bot, nodejs, open-source, spotify, youtube, yt-dlp
- Language: JavaScript
- Homepage: https://melody-bot.mcbabel.de
- Size: 307 KB
- Stars: 5
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ๐ถ Discord Music Bot
A feature-rich Discord music bot built with **discord.js v14** and **Node.js**. Supports 9 streaming services including YouTube, Spotify, SoundCloud, Bandcamp, Apple Music, Deezer, and Tidal โ plus lyrics fetching via Genius, custom playlists, queue management, and more โ all through modern slash commands.
---
## Table of Contents
- [Features](#features)
- [Commands](#commands)
- [Prerequisites](#prerequisites)
- [Installation](#installation)
- [Configuration](#configuration)
- [Running](#running)
- [YouTube Authentication (cookies.txt)](#youtube-authentication-cookiestxt)
- [Getting Spotify Credentials](#getting-spotify-credentials)
- [Getting a Genius API Key](#getting-a-genius-api-key)
- [Discord Bot Permissions](#discord-bot-permissions)
- [Tech Stack](#tech-stack)
- [Project Structure](#project-structure)
- [Contributing](#contributing)
- [License](#license)
## Features
- ๐ต **Multi-Service Playback** โ Play from YouTube, SoundCloud, Bandcamp, and direct URLs natively via yt-dlp
- ๐ข **Spotify Integration** โ Paste a Spotify track link and the bot resolves it to YouTube for playback
- ๐ **Apple Music Support** โ Paste an Apple Music track link โ metadata is resolved via free API, then played via YouTube
- ๐ **Deezer Support** โ Paste a Deezer track link โ metadata is resolved via free API, then played via YouTube
- ๐ **Tidal Support** โ Paste a Tidal track link โ metadata is resolved via free API, then played via YouTube
- ๐ป **Radio & Direct URLs** โ Stream internet radio (Icecast/Shoutcast) or direct audio files (.mp3, .wav, .ogg, .flac, .m4a)
- ๏ฟฝ **Lyrics Fetching** โ Retrieve song lyrics from the Genius API
- ๐ **Queue Management** โ View, skip, loop, and control the playback queue
- ๐ **Song Crossfade** โ Smooth transitions between tracks with configurable crossfade duration and pre-buffering
- ๐ **Volume Control** โ Adjust playback volume from 0โ100%
- ๐ณ๏ธ **Vote Skip** โ Democratic skip voting for shared listening sessions
- ๐ถ **Custom Playlists** โ Save and play user-created playlists
- โฑ๏ธ **Now Playing** โ See what's currently playing with track details and source indicator
- ๐ค **Auto-Disconnect** โ Leaves the voice channel after 3 minutes of inactivity
- ๐งน **Message Cleanup** โ Bulk-delete messages with the `/clear` command
### ๐ต Supported Services
| Service | Type | API Key Required |
|---------|------|-----------------|
| YouTube | Direct Streaming (yt-dlp) | No |
| Spotify | Metadata โ YouTube | Yes (Client ID + Secret) |
| SoundCloud | Direct Streaming (yt-dlp) | No |
| Bandcamp | Direct Streaming (yt-dlp) | No |
| Apple Music | Metadata โ YouTube | No |
| Deezer | Metadata โ YouTube | No |
| Tidal | Metadata โ YouTube | No |
| Direct URLs | HTTP Stream (.mp3, .wav, etc.) | No |
| Internet Radio | HTTP Stream | No |
## Commands
### ๐ต Music
| Command | Description |
|---|---|
| `/play ` | Play a song by name, URL (YouTube, Spotify, SoundCloud, Bandcamp, Apple Music, Deezer, Tidal), or direct audio link |
| `/pause` | Pause the current playback |
| `/resume` | Resume paused playback |
| `/skip` | Skip the current track |
| `/stop` | Stop playback and clear the queue |
| `/queue` | Show the current queue |
| `/nowplaying` | Show the currently playing track |
### ๐ Controls
| Command | Description |
|---|---|
| `/volume ` | Set the playback volume (0โ100) |
| `/loop ` | Toggle loop for the current track |
| `/vote_skip` | Vote to skip the current track |
### ๐ Lyrics
| Command | Description |
|---|---|
| `/lyrics` | Fetch lyrics for the currently playing song |
### ๐ถ Playlists
| Command | Description |
|---|---|
| `/add_to_playlist ` | Add a song to a custom playlist |
| `/play_playlist ` | Play a saved playlist |
| `/list_playlists` | List all saved playlists |
### ๐ Voice
| Command | Description |
|---|---|
| `/join` | Join your voice channel |
| `/leave` | Leave the voice channel |
### ๐งน Utility
| Command | Description |
|---|---|
| `/clear ` | Delete recent messages (1โ100, requires Manage Messages) |
| `/settings` | Manage server settings (audio, moderation, display) |
| `/help` | Show all available commands |
## โ๏ธ Server Settings
The bot supports **10 customizable per-server settings** across three categories: **Audio**, **Moderation**, and **Display**. Server admins can fine-tune the bot's behavior using `/settings`.
| Setting | Default | Range |
|---------|---------|-------|
| Default Volume | 50% | 1-100 |
| Max Queue Size | 100 | 10-500 |
| Inactivity Timeout | 3 min | 30-600s |
| Max Song Duration | Unlimited | 0-3600s |
| Crossfade Duration | 0 (off) | 0-10s |
| Vote Skip Threshold | 50% | 1-100 |
| DJ Role | None | Any role |
| Text Channel | Any | Any channel |
| Voice Channel | Any | Any channel |
| Embed Color | #8b5cf6 | Any hex |
Use `/settings view` to see current settings, or `/settings audio`, `/settings moderation`, `/settings display` to configure specific categories. Use `/settings reset` to restore defaults. Requires the **Manage Guild** permission.
## Prerequisites
Before running the bot, make sure you have the following installed:
| Requirement | Details |
|---|---|
| **Node.js** | v18.0.0 or higher โ [Download](https://nodejs.org/) |
| **yt-dlp** | Must be installed and available in your system PATH โ [Install guide](https://github.com/yt-dlp/yt-dlp#installation) |
| **FFmpeg** | Auto-bundled via `ffmpeg-static`, but a system install also works โ [Download](https://ffmpeg.org/download.html) |
| **Discord Bot Token** | Create a bot at the [Discord Developer Portal](https://discord.com/developers/applications) |
| **Spotify API Credentials** | Client ID + Client Secret from the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard) |
| **Genius API Token** | Client Access Token from [Genius API Clients](https://genius.com/api-clients) |
## Installation
1. **Clone the repository:**
```sh
git clone https://github.com/MCbabel/discord-music-bot.git
cd discord-music-bot
```
2. **Install dependencies:**
```sh
npm install
```
## Configuration
Create a `.env` file in the project root with the following required variables:
```env
DISCORD_TOKEN=your_discord_bot_token
SPOTIFY_CLIENT_ID=your_spotify_client_id
SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
GENIUS_ACCESS_TOKEN=your_genius_access_token
```
> **Tip:** You can copy the structure above or reference the environment variables in [`src/config.js`](src/config.js) for the full list.
All four variables are **required** โ the bot will exit with an error message if any are missing.
## Running
Start the bot with:
```sh
npm start
```
Or directly:
```sh
node src/index.js
```
For development with auto-restart on file changes:
```sh
npm run dev
```
## YouTube Authentication (cookies.txt)
Some YouTube videos are age-restricted or region-locked. To access them, you can provide a `cookies.txt` file exported from your browser.
**When is this needed?**
- Age-restricted videos return errors without authentication
- Some region-locked content requires a logged-in session
**How to set it up:**
1. See [`cookies.txt.example`](cookies.txt.example) for detailed instructions
2. Export your YouTube cookies using a browser extension like "Get cookies.txt LOCALLY" or via `yt-dlp --cookies-from-browser`
3. Save the file as `cookies.txt` in the project root
4. Restart the bot โ it will automatically detect and use the cookies
## Getting Spotify Credentials
1. Go to the [Spotify Developer Dashboard](https://developer.spotify.com/dashboard) and log in
2. Click **Create an App** and fill in the required details
3. Copy your **Client ID** and **Client Secret** from the app dashboard
4. Add them to your `.env` file as `SPOTIFY_CLIENT_ID` and `SPOTIFY_CLIENT_SECRET`
## Getting a Genius API Key
1. Go to the [Genius API Clients](https://genius.com/api-clients) page and log in or create an account

2. Click **Create an API Client** and fill in the app details

3. Copy your **Client Access Token**

4. Add it to your `.env` file as `GENIUS_ACCESS_TOKEN`
## Discord Bot Permissions
Invite the bot to your server with the necessary permissions using the OAuth2 URL generator in the [Discord Developer Portal](https://discord.com/developers/applications). The bot requires:
- **View Channels** โ See text channels
- **Send Messages** โ Respond to commands
- **Embed Links** โ Send rich embed messages
- **Read Message History** โ Context for commands like `/lyrics`
- **Manage Messages** โ Required for the `/clear` command
- **Connect** โ Join voice channels
- **Speak** โ Play audio in voice channels
- **Use Slash Commands** โ Register and respond to slash commands
## Tech Stack
| Technology | Purpose |
|---|---|
| [discord.js](https://discord.js.org/) v14 | Discord API framework |
| [@discordjs/voice](https://github.com/discordjs/discord.js/tree/main/packages/voice) | Voice connection & audio streaming |
| [@discordjs/opus](https://github.com/discordjs/opus) | Opus audio encoding |
| [yt-dlp](https://github.com/yt-dlp/yt-dlp) | YouTube audio extraction (subprocess) |
| [play-dl](https://github.com/play-dl/play-dl) | YouTube search |
| [ffmpeg-static](https://github.com/eugeneware/ffmpeg-static) | Bundled FFmpeg binary |
| [spotify-web-api-node](https://github.com/thelinmichael/spotify-web-api-node) | Spotify metadata โ YouTube bridge |
| [genius-lyrics](https://github.com/zyrouge/genius-lyrics) | Lyrics fetching |
| [dotenv](https://github.com/motdotla/dotenv) | Environment variable management |
| [sodium-native](https://github.com/sodium-friends/sodium-native) | Voice encryption |
## Project Structure
```
src/
โโโ index.js # Entry point โ client setup, command registration
โโโ config.js # Configuration & environment variable validation
โโโ messages.js # Discord embed builders (now playing, queue, errors, etc.)
โโโ audio/
โ โโโ player.js # GuildPlayer โ per-guild queue & playback management
โ โโโ resolver.js # Unified URL/query resolver โ auto-detects 9 services
โ โโโ crossfade.js # Crossfade engine โ pre-buffering & volume transitions
โ โโโ stream.js # Stream creation for all source types
โ โโโ youtube.js # yt-dlp integration โ search, stream, info extraction
โ โโโ spotify.js # Spotify โ YouTube bridge (resolve track metadata)
โ โโโ applemusic.js # Apple Music โ YouTube bridge (free API)
โ โโโ deezer.js # Deezer โ YouTube bridge (free API)
โ โโโ tidal.js # Tidal โ YouTube bridge (free API)
โโโ commands/
โ โโโ index.js # All 20 slash command definitions & handlers
โโโ i18n/
โ โโโ index.js # i18n engine (EN, DE, ES)
โ โโโ locales/ # Locale JSON files
โโโ services/
โโโ lyrics.js # Genius lyrics fetching
โโโ playlist.js # Playlist persistence (JSON file storage)
โโโ settings.js # Per-guild settings management
```
## Contributing
Contributions are welcome! Fork this repository and submit a pull request with your changes. Please make sure any modifications are clearly documented.
## Planned Features
- [x] Lyrics fetching using Genius API
- [x] Music playback controls via buttons
- [x] Custom playlists
- [x] Voting to skip songs
- [x] Auto-disconnect after inactivity
- [x] Volume control
- [x] User-specific playlists
- [x] Song search functionality
- [x] Now playing message with song progress
- [x] Integration with more streaming services (SoundCloud, Bandcamp, Apple Music, Deezer, Tidal, Direct URLs, Radio)
- [x] Customizable bot settings
- [x] Song crossfade: Smoothly transition between songs with a configurable crossfade duration.
- [ ] DJ Mode: Allow certain users to have elevated control over the bot, including song reordering and queue management.
- [ ] Genre and Mood Playlists: Generate playlists based on specific genres or moods using AI recommendations.
- [ ] Scheduled Playlists: Schedule specific playlists to play at designated times (e.g., morning playlists or weekend vibes).
- [ ] Karaoke Mode: Display scrolling lyrics in sync with the song for a karaoke experience.
- [ ] Advanced Equalizer: Allow users to adjust bass, treble, and other sound settings for a customized listening experience.
- [ ] Real-time Voting for Upcoming Songs: Users can vote on which song in the queue should play next.
- [ ] Music Trivia Game: Add a fun music quiz game that users can play in the server.
- [ ] Save Favorite Tracks: Users can save their favorite tracks and easily access them for future playback.
## License
This project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for full terms.
---
Happy listening! ๐ต