
Self-taught Projects
Discord Music Bot
A lightweight, personal-use Discord music bot designed for cost-efficient deployment and optimized performance on minimal server resources.
- Hosting: Fly.io (Legacy Hobby plan, Singapore)
- Resources: Shared CPU (x1) + 256MB RAM
- Cost: ~$1.40/month (effectively free since Fly.io waives costs under $5/month for legacy users)
The bot's architecture is highly optimized, ensuring smooth operation within strict resource limits.
Optimization Highlights:
- OpenSSL: Provides secure TLS/SSL connections required for encrypted audio streaming.
- Opus: High-performance audio codec for low-latency, high-quality voice transmission in Discord.
- Sodium: Cryptographic library used for authentication and secure voice communication.
- FFmpeg: Custom-built from source, stripped to essential configs for efficient streaming.
- Alpine: Ultra-lightweight base image utilizing multi-stage builds for optimized production deployment.
- Base image:
alpine:x.x~12.79 MB - Compiled executable (bytecode): ~121.1 MB (via
bun build --compile --bytecode ...)- Bun runtime: ~104.82 MB
- N-API modules:
- DAVE (Discord Audio & Video E2E Encryption): ~1.7 MB
- Opus: ~0.58 MB
- App size: 1 MB
- Precompiled bytecode: ~8 MB
- FFmpeg size: ~17.5 MB (via
./configure --disable-everything ... && make install)
- Base image:
- Custom patches: Implement static-analysis–friendly modifications for the Bun compiler.
- Substitute dynamic NAPI imports from
prism-mediawith a static import ofopus.node - Replace the dynamic detection of FFmpeg sources from
prism-mediawith a staticffmpegcommand - Eliminate the
wsdependency from@discordjs/voiceand@discordjs/wsby using Bun's native WebSocket
- Substitute dynamic NAPI imports from
Development History:
- ~2018: Cloned MusicBot for quick launch locally
- ~2021: Write own bot in Discord.js and Distube
- ~2022: Migrated to TypeScript, Dockerized, added Dependabot, and deployed to Fly.io
- ~2023: Gradual migration to Bun; tweaking custom FFmpeg builds to fix OOM issues caused by npm-installed FFmpeg binary
- Late 2024: Fully stable on Bun. The final build is significantly reduced from ~300 MB to 1 MB
- Mid 2025: Deployed to the home server due to some music providers banned the Fly.io IPs
- Late 2025: Further optimization through custom patches, compiling with Bun, and using a highly stripped-down FFmpeg build (--disable-everything)