A Discord bot that joins a voice channel and plays local audio files from a directory on disk.
It supports fuzzy searching by filename, queuing, shuffle, and playback controls.
- Join/leave voice channels
- Play a song by relative path or fuzzy name
- Queue management: view queue, skip, stop (clear queue), shuffle
- Pause/resume
- Volume control (0–200%)
- Library indexing + manual rescans
- Works with common audio formats supported by your FFmpeg build:
.mp3 .wav .flac .m4a .aac .ogg .opus
- The bot scans
MUSIC_DIRand builds an in-memory index:- keys include the file stem (filename without extension)
- and the relative path without extension
!play <query>:- If
<query>is a real file path, it plays it - Otherwise it finds the best fuzzy match from the library index
- If
Audio playback is handled via Discord voice + FFmpeg (discord.FFmpegPCMAudio).
- Python 3.10+ recommended
- A Discord application + bot token
- FFmpeg installed and reachable (or provide full path)
- Voice dependencies:
discord.py[voice](already in requirements)PyNaClis required for Discord voice (the bot fails early with a helpful message if missing)
git clone <your-repo-url>
cd melody-cafe
python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
python -m pip install -U pip
pip install -r requirements.txtCopy the example env file:
# Windows (PowerShell)
copy .env.example .env
# macOS/Linux
cp .env.example .envEdit .env and set:
DISCORD_TOKEN="your_real_token"
MUSIC_DIR=C:\Path\To\Your\Music\Directory
FFMPEG_PATH=ffmpeg # or full path like C:\ffmpeg\bin\ffmpeg.exe
COMMAND_PREFIX=!Notes:
MUSIC_DIRshould point to a folder containing audio files (it can include subfolders).FFMPEG_PATHcan be justffmpegif it’s on your PATH. Otherwise set the full executable path.COMMAND_PREFIXdefaults to!if omitted.
This bot uses prefix commands and sets:
INTENTS.message_content = TrueYou must also enable Message Content Intent in the Discord Developer Portal for your bot, or commands won’t register.
python bot.pyYou should see something like:
Logged in as <botname> (id: ...)
------
[INFO] Indexed ... entries from <MUSIC_DIR>
All commands assume the default prefix ! (configurable via .env).
-
!join
Join the caller’s voice channel. -
!leave
Disconnect from voice.
-
!play <query>
Play a local track by fuzzy name or by path.Examples:
!play songname!play subfolder/songname!play C:\Music\Albums\Artist\Track01.mp3(works if that exact file exists)
-
!playall [shuffle]
Queue everything in the library. Optionalshuffleto randomize. -
!pause/!resume
Pause/resume playback. -
!skip
Skip the current track. -
!stop
Stop playback and clear the queue. -
!volume <0-200>
Set playback volume in percent (e.g.!volume 120).
-
!queueor!q
Show “Now playing” and the next 20 queued items. -
!shuffle
Shuffle the current queue. -
!list [page] [per_page]
List library entries (defaults: page 1, 20 per page, clamped to 5–50). -
!search <query>
Show best match without queuing it. -
!rescan
Rebuild the library index fromMUSIC_DIR. -
!where
Show the currentMUSIC_DIRandFFMPEG_PATH.
MIT. See LICENSE.