discord-musicbot

repository·v5·Indexed 25 days ago

https://github.com/itzsudhan/discord-musicbot

A Discord music bot built with Discord.js and Lavalink. Version 5.0.0-beta features a Next.js dashboard, slash commands for music control (loop, 24/7 mode, autoqueue, filters), and a context menu command to play songs from message content. It requires Node.js 16+ and a working Lavalink server. The bot includes administrative tools like /guildleave and /clean, and can be deployed via Docker or manual installation.

Tokens
7.1K
Snippets
18
Records
63
Agent score
84%

What's inside discord-musicbot

  1. Install and run via Non-Docker (Manual) method

    v5

    To run the bot directly on your host machine:

    1. Configure the config.js file first. Ensure you add a valid Lavalink host.
    2. Install dependencies and deploy slash commands:
    npm install
    npm run deploy
    1. Start the bot:
    node index.js
    npm install
    npm run deploy
    node index.js
  2. Install and run using Docker

    v5

    To run the bot using Docker, first configure the config.js file. Set the Lavalink host to "lavalink" and ensure the password and port match the specifications in docker/application.yml.

    Then, build and start both the bot and Lavalink using:

    docker-compose up -d --build
  3. Migrating from v4 to v5

    v5

    If you are upgrading from version 4 to version 5, follow these steps:

    1. Download and configure v5 in a separate folder.
    2. Kick the existing bot out of your Discord server.
    3. Reinvite the bot using the correct scopes. An example invite URL format is: https://discord.com/oauth2/authorize?client_id=CLIENT_ID&permissions=277083450689&scope=bot%20applications.commands (replace CLIENT_ID with your actual client ID).
    4. Run npm run deploy or yarn deploy to initialize the slash commands.
  4. Prerequisites for Discord Music Bot

    v5

    Before installing or running the bot, ensure you have the following requirements met:

    • Node.js: Version 16 or higher.
    • Lavalink Server: A working Lavalink server is required for all music functionality.
    • Slash Command Initialization: You must run npm run deploy or yarn deploy to initialize slash commands. This can be performed on your local machine.
  5. Deploy Discord Music Bot using Docker Compose

    v5

    You can deploy the Discord Music Bot and a Lavalink instance using Docker Compose. The setup requires a local config.js file for the bot configuration and a docker/application.yml file for the Lavalink configuration. The services are connected via a shared network named lavalink-net.

    version: "3"
    
    services:
      discord-musicbot:
        build: .
        image: discord-musicbot:latest
        container_name: discord-musicbot
        restart: unless-stopped
        networks:
          - lavalink-net
        depends_on:
          - lavalink
        volumes:
          - ./config.js:/usr/src/app/config.js:ro
    
      lavalink:
        image: fredboat/lavalink:3.7.12
        container_name: music-lavalink
        hostname: lavalink
        restart: unless-stopped
        networks:
          - lavalink-net
        volumes:
          - ./docker/application.yml:/opt/Lavalink/application.yml:ro
    
    networks:
      lavalink-net:
  6. Configure Server authentication and sessions

    v5

    The Server class uses express-session and passport-discord for authentication. It relies on the following configuration keys from your project's config file:

    • cookieSecret: The secret used for session signing.
    • website: The base URL of your website (used to determine if cookies should be secure and to set the Passport callbackURL).
    • clientId: Discord Application Client ID.
    • clientSecret: Discord Application Client Secret.
    • scopes: An array of Discord OAuth2 scopes (the server automatically filters out scopes starting with app).
    • port: The port on which the Express server will listen.
  7. Configure Discord Music Bot volumes

    v5

    When running the discord-musicbot service via Docker, you must mount your local configuration file to the container. The bot expects the configuration at /usr/src/app/config.js inside the container. It is recommended to mount it as read-only (:ro).

    volumes:
      - ./config.js:/usr/src/app/config.js:ro
  8. Configure Lavalink volumes

    v5

    When running the lavalink service via Docker, you must mount your Lavalink application configuration to the container. The configuration file should be mapped to /opt/Lavalink/application.yml inside the container. It is recommended to mount it as read-only (:ro).

    volumes:
      - ./docker/application.yml:/opt/Lavalink/application.yml:ro
  9. Track message deletion state

    v5

    The client includes utility methods to manage and check the deletion state of messages within its runtime via a WeakSet:

    • markMessageAsDeleted(message): Adds a message to the internal deletedMessages set.
    • isMessageDeleted(message): Returns true if the message has been marked as deleted.