Skip to content

A feature-rich Discord music bot built with Discord.js v14 and Lavalink, supporting both slash commands and prefix commands with interactive buttons.

Notifications You must be signed in to change notification settings

friday2su/lavalink-music-bot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Discord Lavalink Music Bot

A feature-rich Discord music bot built with Discord.js v14 and Lavalink, supporting both slash commands and prefix commands with interactive buttons.

Features

  • 🎵 High-quality music playback using Lavalink
  • 🎛️ Interactive controls with Discord v2 components (buttons)
  • Dual command support - Both slash commands (/) and prefix commands (!)
  • 🔄 Loop modes - Track, Queue, or Off
  • 🔀 Queue management - Shuffle, skip, stop, pause/resume
  • 📋 Queue display with pagination
  • 🔊 Volume control (1-100%)
  • 🎯 Multiple music sources - YouTube, Spotify, SoundCloud, and more
  • 📱 Clean, modern embeds with progress bars and track information
  • 🛡️ Permission checks and error handling
  • ⏱️ Command cooldowns to prevent spam

Supported Music Sources

  • YouTube & YouTube Music
  • Spotify (track links)
  • SoundCloud
  • Direct audio URLs
  • Search queries

Commands

Slash Commands (/)

  • /play <query> - Play a song or playlist
  • /pause - Pause or resume the current song
  • /skip - Skip the current song
  • /stop - Stop music and clear queue
  • /nowplaying - Show current song information
  • /queue [page] - Display the music queue
  • /volume [level] - Set or check volume (1-100)
  • /loop <mode> - Set loop mode (off/track/queue)
  • /shuffle - Shuffle the queue
  • /help - Show all commands

Prefix Commands (!)

  • !play <query> - Play a song or playlist
  • !pause - Pause or resume the current song
  • !skip - Skip the current song
  • !stop - Stop music and clear queue
  • !np - Show current song information
  • !queue [page] - Display the music queue
  • !volume [level] - Set or check volume (1-100)
  • !loop [mode] - Set loop mode (off/track/queue)
  • !shuffle - Shuffle the queue
  • !help - Show all commands

Interactive Controls

Use the buttons below music messages for quick controls:

  • ⏸️ Pause/Resume
  • ⏭️ Skip
  • ⏹️ Stop
  • 🔀 Shuffle
  • 🔁 Loop

Installation

Prerequisites

  1. Node.js (v16.9.0 or higher)
  2. Lavalink Server (v3.7 or higher)
  3. Discord Bot Token

Setup

  1. Clone the repository

    git clone https://github.com/friday2su/lavalink-music-bot.git
    cd lavalink-music-bot
  2. Install dependencies

    npm install
  3. Configure environment variables

    cp .env.example .env

    Edit .env file with your configuration:

    # Discord Bot Configuration
    DISCORD_TOKEN=your_discord_bot_token_here
    CLIENT_ID=your_bot_client_id_here
    
    # Bot Configuration
    PREFIX=!
    OWNER_ID=your_discord_user_id_here
    
    # Lavalink Configuration
    LAVALINK_HOST=localhost
    LAVALINK_PORT=2333
    LAVALINK_PASSWORD=youshallnotpass
    LAVALINK_SECURE=false
  4. Set up Lavalink Server

    Download Lavalink from GitHub Releases

    Create application.yml:

    server:
      port: 2333
      address: 0.0.0.0
    lavalink:
      server:
        password: "youshallnotpass"
        sources:
          youtube: true
          bandcamp: true
          soundcloud: true
          twitch: true
          vimeo: true
          http: true
          local: false
        bufferDurationMs: 400
        frameBufferDurationMs: 5000
        youtubePlaylistLoadLimit: 6
        playerUpdateInterval: 5
        youtubeSearchEnabled: true
        soundcloudSearchEnabled: true
        gc-warnings: true
  5. Start Lavalink

    java -jar Lavalink.jar
  6. Deploy slash commands (optional)

    npm run deploy

    Or directly:

    node src/index.js --deploy

    This manually registers slash commands globally. The bot will also auto-register commands when it starts.

  7. Start the bot

    npm start

Bot Permissions

The bot requires the following permissions:

  • Send Messages
  • Use Slash Commands
  • Embed Links
  • Connect (to voice channels)
  • Speak (in voice channels)
  • Use Voice Activity

Project Structure

src/
├── commands/
│   ├── slash/          # Slash commands
│   └── prefix/         # Prefix commands
├── events/             # Discord.js events
├── utils/              # Utility functions
└── index.js           # Main bot file

Configuration

Environment Variables

Variable Description Required
DISCORD_TOKEN Your Discord bot token Yes
CLIENT_ID Your bot's client ID Yes
PREFIX Command prefix (default: !) No
OWNER_ID Bot owner's Discord user ID No
LAVALINK_HOST Lavalink server host Yes
LAVALINK_PORT Lavalink server port Yes
LAVALINK_PASSWORD Lavalink server password Yes
LAVALINK_SECURE Use secure connection (wss) No

Lavalink Configuration

Make sure your Lavalink server is properly configured with the sources you want to use. The bot supports all sources that Lavalink supports.

Troubleshooting

Common Issues

  1. Bot doesn't respond to commands

    • Check if the bot has proper permissions
    • Verify the bot token is correct
    • Ensure the bot is online
  2. Music doesn't play

    • Check if Lavalink server is running
    • Verify Lavalink connection settings
    • Ensure the bot has voice permissions
  3. Slash commands not showing

    • Wait up to 1 hour for global commands to update
    • Check if the bot has Use Slash Commands permission
    • Restart the bot if commands were recently added

Support

If you encounter any issues:

  1. Check the console for error messages
  2. Verify all configuration settings
  3. Ensure all dependencies are installed
  4. Check Discord and Lavalink server status

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Test thoroughly
  5. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

About

A feature-rich Discord music bot built with Discord.js v14 and Lavalink, supporting both slash commands and prefix commands with interactive buttons.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published