A simple Discord music bot with a per-server queue that plays YouTube audio and supports the most important control commands (play, playnow, skip, pause, resume, stop, volume). It is built with discord.py, yt-dlp, and ffmpeg.
The original bot is based on a YouTube tutorial (see below) but has been updated to use slash commands, yt-dlp, and Docker.
- Slash commands (application commands)
/play– Play a song or add it to the queue (YouTube URL or search query)/playnow– Play a song immediately and interrupt the current playback/skip– Skip the currently playing song/pause– Pause the current playback/resume– Resume paused playback/stop– Stop playback, clear the queue, and leave the voice channel/volume– Set the volume for future songs (0–100%)
- Server-specific queue (one queue per guild)
- Volume control via FFmpeg audio filter
- Ready-to-use Docker image:
docker.io/poldion/musicbot
Original tutorial video: https://youtu.be/U5CUkxUh2CQ
- A Discord account and a bot application in the Discord Developer Portal
- The bot must be invited to your server with the required permissions for voice and slash commands
- Python 3.11 (recommended; at least 3.8)
pipffmpegavailable on your system- Linux (Debian/Ubuntu):
sudo apt update sudo apt install ffmpeg
- Windows:
- Download ffmpeg from https://www.ffmpeg.org/download.html, or use a pre-bundled
bin/ffmpegfolder inside your project. - Make sure your code either:
- Uses the system
ffmpeg(viaPATH), or - Explicitly points to your local
bin/ffmpegfolder when creatingFFmpegOpusAudio.
- Uses the system
- Download ffmpeg from https://www.ffmpeg.org/download.html, or use a pre-bundled
- Linux (Debian/Ubuntu):
The bot reads the Discord token from the environment variable DISCORD_TOKEN. The easiest way is to create a .env file in the project directory:
DISCORD_TOKEN=YOUR_DISCORD_TOKEN_HEREThe file is automatically loaded via python-dotenv.
The pre-built image is available at: docker.io/poldion/musicbot.
See the official docs: https://docs.docker.com/engine/install/
Create a .env file in any directory:
DISCORD_TOKEN=YOUR_DISCORD_TOKEN_HEREIn the directory where your .env file is located:
docker run --rm \
--name musicbot \
--env-file .env \
docker.io/poldion/musicbot:latest--rmremoves the container after it stops--env-file .envpasses the Discord token into the container
Optionally run it in the background (detached):
docker run -d \
--name musicbot \
--env-file .env \
docker.io/poldion/musicbot:latestView logs:
docker logs -f musicbotWith Docker Compose you can manage the bot easily via docker compose up -d.
Create a file called docker-compose.yml in an empty directory (or in your project directory) with content similar to this:
version: "3.9"
services:
musicbot:
image: docker.io/poldion/musicbot:latest
container_name: musicbot
restart: unless-stopped
env_file:
- .envAlternatively, you can pass the token directly as an environment variable in the compose file (less secure, but sometimes convenient):
version: "3.9"
services:
musicbot:
image: docker.io/poldion/musicbot:latest
container_name: musicbot
restart: unless-stopped
environment:
DISCORD_TOKEN: "YOUR_DISCORD_TOKEN_HERE"In the same directory:
DISCORD_TOKEN=YOUR_DISCORD_TOKEN_HEREdocker compose up -ddocker compose logs -fshows you the logsdocker compose downstops the bot
If you want to run the bot directly on your system with Python:
git clone https://github.com/YOUR_GITHUB_USERNAME/discord-music-bot-remastered.git
cd discord-music-bot-remastered(Adjust the URL to match your repository if you forked or renamed it.)
python -m venv .venv
source .venv/bin/activate # Linux/macOS
# .venv\Scripts\activate # Windows (PowerShell/CMD)pip install -r requirements.txtIf you prefer not to use requirements.txt, you can install the required packages manually:
pip install discord.py python-dotenv yt-dlp PyNaClDISCORD_TOKEN=YOUR_DISCORD_TOKEN_HEREpython MusicBot.pyThe console should show something similar to:
Starte Bot...("Starting bot..." – log message in German)<BotName> is online!- An invite link for your bot
If you want to build your own image or customize the bot, you can use the provided Dockerfile.
- Docker installed
- Project source code available (e.g., cloned from your fork)
In the project directory (where Dockerfile and MusicBot.py are located):
docker build -t musicbot:latest .This will create a local image called musicbot:latest.
# in the directory containing your .env
docker run --rm \
--name musicbot \
--env-file .env \
musicbot:latestIf you want to use your own Docker Hub repository (or another registry):
# Example: your Docker Hub username is "yourname"
docker tag musicbot:latest yourname/musicbot:latest
docker login
# Enter your Docker Hub username and password/token
docker push yourname/musicbot:latestIn your docker-compose.yml you can then replace docker.io/poldion/musicbot:latest with your own image:
services:
musicbot:
image: yourname/musicbot:latest
container_name: musicbot
restart: unless-stopped
env_file:
- .env- Bot is offline / never appears online:
- Double-check that
DISCORD_TOKENis set correctly (no extra spaces, correct bot token). - Make sure the bot is enabled in the Developer Portal and that the correct intents are turned on (e.g. Message Content Intent if needed).
- Double-check that
- No audio / no sound in the voice channel:
- Ensure
ffmpegis installed (locally), or installed in the container (the Dockerfile in this repo already installsffmpeg). - On Windows, verify that your code points to the correct
ffmpegbinary (either viaPATHor a localbin/ffmpegfolder).
- Ensure
- Slash commands are not visible:
- Wait a few minutes for Discord to propagate and sync the commands.
- Make sure the bot is invited to the correct server.
If you want to support additional platforms (e.g. Raspberry Pi, ARM, specific cloud providers), the README can be extended with platform-specific notes.