Skip to main content
MusicBot is a Discord bot that brings YouTube music playback directly to your Discord voice channels. Built with Python and discord.py, it provides a seamless music streaming experience for your Discord community.

What is MusicBot?

MusicBot connects to your Discord voice channels and plays audio from YouTube videos. Simply provide a song name or YouTube URL, and the bot will download, cache, and stream the audio to your voice channel. The bot is designed for multi-server environments with guild-specific queue management, automatic caching, and intelligent inactivity handling.

Key features

YouTube integration

Search for songs by name or use direct YouTube URLs. The bot uses the YouTube Data API v3 for intelligent search results.

Queue management

Add multiple songs to a queue. Each Discord server has its own independent queue and playback state.

Smart caching

Downloaded songs are cached per server to reduce bandwidth and improve playback speed for repeated requests.

Auto-disconnect

The bot automatically leaves voice channels after 5 minutes of inactivity to free up resources.

Use cases

Community music sessions
Let your community members queue up their favorite songs and enjoy music together in voice channels.
Background music
Provide ambient music for gaming sessions, study groups, or casual hangouts.
Personal DJ
Quickly play music on demand without leaving Discord or switching apps.

How it works

MusicBot uses several key technologies:
  • discord.py - Connects to Discord and handles voice channel operations
  • yt-dlp - Downloads and extracts audio from YouTube videos
  • FFmpeg - Processes and streams audio to Discord voice channels
  • YouTube Data API v3 - Searches for videos based on user queries
Each Discord server gets its own playback state, queue, and cache directory. This ensures that multiple servers can use the bot simultaneously without conflicts.

Architecture highlights

The bot implements a GuildPlayerState class that encapsulates all playback-related state for each Discord server:
class GuildPlayerState:
    def __init__(self, guild_id: int, bot_instance: commands.Bot):
        self.guild_id: int = guild_id
        self.queue: list[str] = []  # List of file paths for songs
        self.song_titles: list[str] = []  # List of song titles
        self.current_song_path: str | None = None
        self.voice_client: discord.VoiceClient | None = None
        self.inactive_timer: asyncio.TimerHandle | None = None
This architecture allows the bot to:
  • Manage multiple servers simultaneously
  • Maintain separate queues for each server
  • Handle server-specific caching and cleanup
  • Track inactivity independently per server

Next steps

Quickstart

Get your bot running in under 10 minutes

Commands

Learn all available bot commands

Build docs developers (and LLMs) love