An open API service indexing awesome lists of open source software.

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).

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.


Version
License
Node
discord.js
9 Services
yt-dlp
FFmpeg
i18n
GitHub Stars
GitHub Downloads

---

## 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

![Genius API Account](Images/Genius_API_Account.png)

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

![Create API Client](Images/Create_API_Client.png)

3. Copy your **Client Access Token**

![Retrieve API Key](Images/Retrieve_API_Key.png)

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! ๐ŸŽต