Skip to content

keshon/melodix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

72 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

# Header

GoDoc Go report

🎡 Melodix β€” Self-hosted Discord music bot

Melodix is my pet project written in Go that plays audio from YouTube and audio streaming links to Discord voice channels. It's a continuation of my original buggy prototype.

🌟 Features Overview

🎧 Playback Support

  • 🎢 Track added by song name or YouTube/Soundcloud link.
  • πŸ“» Internet radio streaming links (24/7 playback).

βš™οΈ Additional Features

  • 🌐 Operation across multiple Discord servers.
  • πŸ“œ Access to recent track statistics and history of play commands.
  • πŸ”„ Playback auto-resume support for connection interruptions.

⚠️ Current Limitations

  • ⏸️ Playback auto-resume feature may cause noticeable pauses at times.
  • ⏩ Playback speed may sometimes slightly vary.
  • 🚫 The bot cannot play YouTube live streams or region-locked videos.
  • 🚫 Not every radio streams are supported.
  • 🐞 Can hang or become unresponsive. It's not bug-free.

πŸš€ Try Melodix

You can test out Melodix in two ways:

  • πŸ–₯️ Download compiled binaries (available only for Windows). Ensure FFMPEG is installed on your system and added to the global PATH variable. Follow the "Create bot in Discord Developer Portal" section to set up the bot in Discord.

  • πŸŽ™οΈ Join the Official Discord server and use the voice and #bot-spam channels.

πŸ“ Available Discord Commands

▢️ Playback Commands

  • !play [title|url] β€” Parameters: song name, YouTube URL, audio streaming URL.
  • !play fast [title|url] β€” Manually select faster parser (YouTube only).
  • !play slow [title|url] β€” Manually select slower parser (YouTube and SoundCloud).
  • !skip β€” Skip to the next track in the queue.
  • !stop β€” Stop playback, clear the queue, and leave the voice channel.

πŸ“‹ Advanced Playback Commands

  • !list β€” Show the current song queue.
  • !pause, !resume β€” Pause/resume current playback.

πŸ“Š Information Commands

  • !now β€” Show the currently playing song. Convenient for radio streaming.
  • !stats β€” Show track statistics with total playback duration and count.
  • !log β€” Show recent play commands by users.

βš™οΈ Utility Commands

  • !cache [on|off] β€” Enable/disable caching during playback (⚠️ experimental).
  • !set-prefx [new_prefix] β€” Set a custom prefix for a guild to avoid collisions with other bots.
  • melodix-reset-prefix β€” Revert to the default prefix !.

ℹ️ General Commands

  • !about β€” Show bot information.
  • !help β€” Show a help cheatsheet.

πŸ’‘ Usage Examples

To use the play command, provide a YouTube video title or URL:

!play Never Gonna Give You Up
!play https://www.youtube.com/watch?v=dQw4w9WgXcQ
!play http://stream-uk1.radioparadise.com/aac-320

Play multiple tracks, the second track will be added to the queue (works only with links):

!play https://www.youtube.com/watch?v=dQw4w9WgXcQ https://www.youtube.com/watch?v=OorZcOzNcgE

Play a track with a predefinied parsing mode:

!play fast https://www.youtube.com/watch?v=dQw4w9WgXcQ
!play slow https://www.youtube.com/watch?v=dQw4w9WgXcQ

⚑Fast and 🐒 Slow Parsing Modes

Melodix uses two different parser packages to retrieve streaming links from YouTube and SoundCloud:

  • Fast Mode: youtube by Kkdai. This parser is very fast but can sometimes be unreliable and works only for YouTube.
  • Slow Mode: go-ytdlp by lrstanley. This is a Go wrapper library for the well-known yt-dlp, a powerful command-line audio/video downloader. It is more reliable but noticeably slower.

By default, Melodix tries to use the fast parser first. If it fails, it falls back to the slower one.

πŸ”§ How to Set Up the Bot

πŸ”— Create a Bot in the Discord Developer Portal

To add Melodix to a Discord server, follow these steps:

  1. Create an application in the Discord Developer Portal and obtain the APPLICATION_ID (in the General section).
  2. In the Bot section, enable PRESENCE INTENT, SERVER MEMBERS INTENT, and MESSAGE CONTENT INTENT.
  3. Use the following link to authorize the bot: discord.com/oauth2/authorize?client_id=YOUR_APPLICATION_ID&scope=bot&permissions=36727824
    • Replace YOUR_APPLICATION_ID with your Bot's Application ID from step 1.
  4. Select a server and click "Authorize".
  5. Grant the necessary permissions for Melodix to function correctly (access to text and voice channels).

After adding the bot, build it from source or download compiled binaries. Docker deployment instructions are available in docker/README.md.

πŸ› οΈ Building Melodix from Sources

This project is written in Go, so ensure your environment is ready. Use the provided scripts to build Melodix from source:

  • bash-and-run.bat (or .sh for Linux): Build the debug version and execute.
  • build-release.bat (or .sh for Linux): Build the release version.
  • build-dist-assemble: Build the release version and assemble it as a distribution package (Windows only).

Rename .env.example to .env and store your Discord Bot Token in the DISCORD_TOKEN variable. Install FFMPEG and add it to global PATH variable. Install yt-dlp and add it to global PATH variable.

🐳 Docker Deployment

For Docker deployment, refer to docker/README.md for specific instructions.

πŸ“ Environment Variables

You can configure Melodix using environment variables by creating a .env file in your project root directory. The following variables should be set in your .env file:

# Discord Bot Token (Required)
DISCORD_TOKEN=your-discord-bot-token

# Encoding options
ENCODE_VOLUME=128
ENCODE_CHANNELS=2
ENCODE_FRAME_RATE=48000
ENCODE_FRAME_DURATION=20
ENCODE_BITRATE=96
ENCODE_COMPRESSION_LEVEL=10
ENCODE_PACKET_LOSS=1
ENCODE_BUFFERED_FRAMES=400
ENCODE_VBR=true
ENCODE_START_TIME=0s
ENCODE_VOLUME_FLOAT=1.0
ENCODE_RECONNECT_AT_EOF=1
ENCODE_RECONNECT_STREAMED=1
ENCODE_RECONNECT_ON_NETWORK_ERROR=1
ENCODE_RECONNECT_ON_HTTP_ERROR="4xx,5xx"
ENCODE_RECONNECT_DELAY_MAX=5
ENCODE_FFMPEG_BINARY_PATH=""
ENCODE_ENCODING_LINE_LOG=true
ENCODE_USER_AGENT="Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)"
ENCODE_RAW_OUTPUT=true

πŸ†˜ Support

For any questions, get support in the Official Discord server.

πŸ“œ License

Melodix is licensed under the MIT License.