A Discord music bot built with Node.js that plays YouTube audio in voice channels with a full queue and playlist system.
- Node.js 18 or later (20 LTS recommended)
- npm
- A Discord bot account (see setup below)
Before running the bot you need a Discord application and bot account. Follow these steps exactly — skipping the intent toggles is the most common reason the bot stops responding.
- Go to discord.com/developers/applications
- Click New Application, give it a name, and confirm.
- In the left sidebar click Bot.
- Click Add Bot → Yes, do it!
- Under Token, click Reset Token and copy it — you will paste this into
config.json. Keep it secret; anyone with this token controls the bot.
Still on the Bot page, scroll down to Privileged Gateway Intents and enable all three:
| Intent | Why it's needed |
|---|---|
| Presence Intent | Recommended on; harmless to leave on |
| Server Members Intent | Required for member-related checks |
| Message Content Intent | Critical — without this the bot cannot read any command you type and will silently ignore all messages |
Click Save Changes.
- In the left sidebar click OAuth2 → URL Generator.
- Under Scopes check
bot. - Under Bot Permissions check:
Read Messages / View ChannelsSend MessagesEmbed LinksAttach FilesRead Message HistoryConnectSpeak
- Copy the generated URL at the bottom and open it in your browser to invite the bot to your server.
# Clone or download the repository
git clone https://github.com/RobertAndion/DiscordMusicBotNode.git
cd DiscordMusicBotNode
# Install dependencies
npm installCopy the sample config and add your bot token:
cp config.sample.json config.jsonOpen config.json and fill in your token:
{
"prefix": "!",
"token": "YOUR_BOT_TOKEN_HERE"
}The prefix can be changed to any character or string you prefer.
node index.jsOr using the npm script:
npm startYou should see Bot is live. in the terminal when it connects.
The default prefix is !. Aliases are listed in parentheses.
| Command | Alias | Description |
|---|---|---|
!play <song name or URL> |
!p |
Join your voice channel and play a song. Adds to queue if already playing. |
!skip [amount] |
— | Skip the current song, or skip multiple songs with an optional number. |
!queue [page] |
!q |
Show the current queue. Use a page number for long queues. |
!pause |
!ps |
Pause the current song. |
!unpause |
!up |
Resume a paused song. |
!shuffle |
— | Shuffle all songs in the queue (keeps the current song in place). |
!clear |
!c |
Clear the entire queue and stop playback. |
!help |
!h |
Show the command list in chat. |
!help playlist |
— | Show playlist command list in chat. |
Playlists are stored per user. Each user's playlists are saved in the Playlists/ folder.
| Command | Alias | Description |
|---|---|---|
!createplaylist <name> |
!cpl |
Create a new playlist with the currently playing song. |
!addtoplaylist <name> |
!atp |
Add the currently playing song to an existing playlist. |
!addqueuetoplaylist <name> |
!aqtp |
Add the entire current queue to a playlist. |
!playfromlist <name> |
!pl, !playl |
Load a playlist into the queue and start playing. |
!listplaylists [page] |
!lpl |
List all your playlists. |
!viewplaylist <name> |
!vpl |
View the songs inside a playlist. |
!deletefromlist <#> <name> |
!dfl, !delsong |
Remove song number # from a playlist. |
!deleteplaylist <name> |
!dl, !deletelist |
Delete an entire playlist. |
!renameplaylist <old> <new> |
!rl, !rename |
Rename a playlist. |
!getplaylist <name> |
!gl, !getlist |
DM you the playlist as a .json file for sharing or backup. |
!uploadplaylist |
!uplist |
Attach a .json playlist file to the message to import it. |
!backupplaylists |
!bups |
DM you a zip of all playlist files (Docker use — see below). |
The Docker/ folder contains a Dockerfile for running the bot in a container.
On your server, create a build directory with this layout before building:
musicbot-build/
├── Dockerfile ← copy from Docker/Dockerfile in this repo
├── Bot/
│ ├── index.js
│ ├── package.json
│ ├── package-lock.json
│ ├── config.json ← create from config.sample.json (add your token)
│ ├── commands/
│ │ ├── ytdltie.js
│ │ └── commandHandler.js
│ ├── Playlists/ ← leave empty or restore from a previous backup
│ └── Logs/ ← leave empty
Files you do not need to copy:
node_modules/— created bynpm installinside the container during buildstartup.sh— obsolete; the Dockerfile'sCMDstarts the bot directlyDocker/musicbotstart.sh— goes on the host, not insideBot/tests/— not needed at runtime
From inside musicbot-build/ (where the Dockerfile sits):
docker build -t musicbot .Run once to create and start the named container:
docker run -d --name musicbot -m 2G --cpuset-cpus 0-1 --security-opt=no-new-privileges musicbot-druns it detached (in the background) — the bot starts automatically via theCMDin the Dockerfile--name musicbotnames the container so the startup script can find it-mand--cpuset-cpusare optional resource limits;--security-opt=no-new-privilegesis recommended
docker stop musicbotdocker container start musicbotmusicbotstart.sh restarts the named container after a system reboot. Place it on the host and add to the host's crontab (crontab -e):
@reboot sh /path/to/musicbotstart.sh
The script waits 30 seconds for Docker to be ready before issuing the start command. This only works after the First Run above has been done at least once (so the named container exists).
You cannot update files inside a running container. Use !backupplaylists to receive a zip of your playlist files before rebuilding. Place the .json files back in the Playlists/ folder before building the new image so they are included automatically.