A lightweight Discord bot for streaming audio to voice channels in private servers. This is a personal project built for fun and learning - not intended as a commercial product or service.
A simple bot implementation for playing audio in Discord voice channels using yt-dlp.
-
Go - Go programming language runtime
- Download from golang.org
- Verify installation with:
go version
-
yt-dlp - Media download utility
- Install from yt-dlp/yt-dlp
- Verify installation with:
yt-dlp --version
-
ngrok - Tunneling service for local development or self-hosting
- Sign up at ngrok.com
- Set up your authtoken and reserved domain
- Required environment variables:
NGROK_AUTHTOKEN
: Your ngrok authentication tokenNGROK_DOMAIN
: Your reserved ngrok domain (this isn't required, but it'll change every time you restart)
- Documentation: ngrok docs
-
Docker - Containerization tool
- Install from Docker
- Verify installation with:
docker --version
-
Gemini - Optional AI integration for song requests. Used to make responses more natural and human-like. It's set to caveman mode by default lol
- Get an API key from Google AI Studio
- Required environment variables:
GEMINI_API_KEY
: Your Gemini API keyGEMINI_ENABLED
: Set to "true" to enable Gemini integration, or "false" to disable it.
-
Create a new application in the Discord Developer Portal
- Documentation: Discord Developer Portal
-
Create a bot for your application
- Documentation: Discord Bot
-
Clone this repository:
git clone https://github.com/benminer/discord-audio-streamer.git cd discord-audio-streamer
-
Set up your environment variables:
cp common.env .env
-
Configure your
.env
file with the required parameters found incommon.env
-
Install dependencies:
go mod download
-
Build the project:
go build -o discord-bot
-
Run the bot:
./discord-bot
-
Build the Docker image:
docker build -t discord-music-bot:latest ./
Note for Apple Silicon users: If you are building the Docker image on an Apple Silicon Mac, you may need to use
docker buildx
to build an image that is compatible with your architecture. For example:docker buildx build --platform linux/amd64 -t discord-music-bot:latest .
-
Run the Docker container:
docker run -d --name discord-music-bot \ --restart always \ --memory="1g" \ --memory-reservation="512m" \ --memory-swap="2g" \ --cpus="2" \ --cpu-shares="2048" \ -e DISCORD_APP_ID=$DISCORD_APP_ID \ -e DISCORD_PUBLIC_KEY=$DISCORD_PUBLIC_KEY \ -e DISCORD_BOT_TOKEN=$DISCORD_BOT_TOKEN \ -e ENFORCE_VOICE_CHANNEL=$ENFORCE_VOICE_CHANNEL \ -e YOUTUBE_API_KEY=$YOUTUBE_API_KEY \ -e GEMINI_API_KEY=$GEMINI_API_KEY \ -e GEMINI_ENABLED=$GEMINI_ENABLED \ -e NGROK_AUTHTOKEN=$NGROK_AUTHTOKEN \ -e NGROK_DOMAIN=$NGROK_DOMAIN \ -e SENTRY_DSN=$SENTRY_DSN \ discord-music-bot:latest
I recommend setting at least 1GB, with 2GB of swap, since songs are stored in memory while streaming.
This project was created for personal use in a private Discord server. While you're welcome to use and modify it, please note it's not maintained as a product or service.
MIT License - See LICENSE file for details.