Files

41 lines
1.6 KiB
Markdown

# discord-bot
A Discord music bot (discord.js v14 + @discordjs/voice, with DAVE E2EE voice support). It plays audio from YouTube and anything else yt-dlp supports, and keeps a local Opus cache so repeated songs start right away. The bot replies in Polish.
This is the version running on the home server (`laptopdell`) as `discordbot.service`.
## Commands (prefix `!`)
| Command | What it does |
|---|---|
| `!play <url or search>` | Queue a track |
| `!fplay <url or search>` | Same, but skips the cache and downloads it again |
| `!skip` / `!queue` / `!stop` / `!leave` | Skip, show the queue, stop and clear it, disconnect |
| `!drop start @a @b @c @d` | Mini-game: rolls a "token" (1:137 500) and a "gold outfit" (1:1 562 500) for each player every second. Also `!drop stop` and `!drop stats` |
| `!help` | List commands |
## How it works
- yt-dlp downloads audio with `--cookies-from-browser firefox` and `player_client=default,web_embedded` (works around yt-dlp#17389). ffprobe reads the duration.
- Tracks longer than 10 s are saved as `cache/<sha>.opus`. `cache/metadata.json` maps URLs to files. Files under 4 KB are treated as broken and downloaded again.
- Volume is fixed at 0.3 (`VOLUME` in `index.js`).
## Setup
```sh
npm install
echo 'DISCORD_TOKEN=...' > .env
node index.js
```
Needs `yt-dlp`, `ffmpeg`, Node 18+, and a Firefox profile logged in to YouTube on the same machine for cookies.
### systemd
`discordbot.service` runs it as user `kq` from `/home/kq/discordbot`:
```sh
sudo cp discordbot.service /etc/systemd/system/
sudo systemctl enable --now discordbot
```