Skip to content

elementaryrock/PerpetuaPlay

Repository files navigation

Discord 24/7 Music Bot

Discord Music Bot Logo

A resource-efficient Discord bot that plays a looping playlist 24/7 in a voice channel. Built with Node.js, discord.js, and @distube/ytdl-core, optimized for Azure VM deployment.


Features

  • Plays a user-defined playlist of YouTube URLs in a Discord voice channel
  • 24/7 looping playback with robust error handling
  • Azure VM optimized - handles cloud infrastructure challenges
  • Bot detection avoidance - uses @distube/ytdl-core with optimized headers
  • Automatic reconnection - recovers from network issues
  • Simple commands: !play, !stop, !skip, !nowplaying, !join, !leave
  • Comprehensive logging - detailed logs for troubleshooting
  • Memory efficient - suitable for small VMs with PM2 management

Setup & Running Instructions

Prerequisites (Ubuntu/Debian Server)

Before installing the bot, your Ubuntu server needs these system dependencies:

# Update package list
sudo apt update

# Install build tools and development packages
sudo apt install -y build-essential python3-dev nodejs npm

# Install libsodium development libraries
sudo apt install -y libsodium-dev

# Install additional build dependencies
sudo apt install -y libtool pkg-config autoconf automake

# Install git if not already installed
sudo apt install -y git

# Install additional tools that might be needed
sudo apt install -y cmake make gcc g++

Why these are needed:

  • build-essential - Essential compilation tools (gcc, make, etc.)
  • libsodium-dev - Required for Discord voice encryption (sodium package)
  • python3-dev - Needed for building native Node.js modules
  • nodejs npm - Node.js runtime and package manager
  • Build tools - Required for compiling native dependencies

1. Clone the Repository

git clone <your-repo-url>
cd "Discord Music bot"

2. Install Dependencies

npm install

3. Configure the Bot

Set your Discord Bot Token

Create a .env file in the project root:

DISCORD_TOKEN=your_bot_token_here

Configure Your Playlist

Edit config/playlist.json with your YouTube URLs:

[
  "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
  "https://www.youtube.com/watch?v=3JZ_D3ELwOQ"
]

4. Validate Configuration (Recommended)

# Test bot token
npm run test:token

# Validate all playlist URLs
npm run test:playlist

# Complete configuration check
npm run config:validate

5. Start the Bot

Quick Start

./start.sh

Manual Start

npm start

Production (24/7 with PM2)

npm run pm2:start

6. Available Commands

  • !play — Join your voice channel and start looping the playlist
  • !stop — Stop playback and leave the channel
  • !skip — Skip to the next song
  • !nowplaying or !np — Show the current song with details
  • !join — Join your voice channel
  • !leave — Leave the voice channel
  • !help — Show available commands

7. Troubleshooting Azure VM Issues

If you encounter "Sign in to confirm you're not a bot" errors on Azure VMs:

# Run Azure optimization script for troubleshooting tips
node scripts/azure-optimization.js

# Check cookie setup instructions
node scripts/setup-cookies.js

Common Azure VM Solutions:

  • ✅ Uses @distube/ytdl-core instead of play-dl (better bot detection avoidance)
  • ✅ Optimized User-Agent headers for cloud environments
  • ✅ Enhanced buffer sizes for Azure network performance
  • ✅ Cookie authentication setup available (see scripts/setup-cookies.js)
  • ✅ Proxy configuration support for IP reputation issues

Alternative Solutions if Issues Persist:

  1. Set up YouTube cookies (instructions in scripts/setup-cookies.js)
  2. Use residential proxy services
  3. Consider different Azure regions
  4. Monitor IP reputation status

Troubleshooting

YouTube "Sign in to confirm you're not a bot" Error

This is common on Azure VMs due to IP reputation issues. The bot now uses @distube/ytdl-core which handles this better, but if you still encounter issues:

  1. Run the optimization script:

    node scripts/azure-optimization.js
  2. Set up YouTube cookies (if needed):

    node scripts/setup-cookies.js
    # Follow the instructions to extract cookies from your browser
  3. Consider using a proxy service for residential IP addresses

  4. Check Azure region - some regions may have better IP reputation

Common Issues

  • Bot doesn't respond: Check Discord token and bot permissions
  • Can't join voice channel: Ensure bot has "Connect" and "Speak" permissions
  • Memory issues: PM2 will restart automatically at 200MB usage
  • Network timeouts: Azure optimization script includes network settings

Getting Help

  • Check docs/memory_bank.md for detailed solutions
  • Run validation scripts: npm run config:validate
  • Monitor logs: npm run pm2:logs

License

MIT

About

A resource-efficient Discord bot that plays a looping playlist 24/7 in a voice channel.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published