# PES League — Discord Bot

Bot Discord untuk input skor pertandingan **ranked** dan **turnamen** langsung dari Discord.

## Setup

### 1. Install dependencies

```bash
cd discord-bot
npm install
```

### 2. Buat file `.env`

Copy dari `.env.example` lalu isi:

```env
DISCORD_TOKEN=      # Bot token dari Discord Developer Portal
DISCORD_CLIENT_ID=  # Application ID dari Discord Developer Portal
DISCORD_GUILD_ID=   # ID server Discord (untuk dev, biar commands langsung muncul)
                    # Kosongkan untuk register global commands

API_URL=http://localhost/pes-league/public/api
BOT_SECRET=         # Harus sama dengan DISCORD_BOT_SECRET di .env Laravel

RESULTS_CHANNEL_ID= # (opsional) Channel ID untuk post hasil pertandingan otomatis
```

### 3. Set `DISCORD_BOT_SECRET` di Laravel `.env`

```env
DISCORD_BOT_SECRET=secret_rahasia_panjang_kamu
```

Secret yang sama harus diisi di `BOT_SECRET` file `.env` bot.

### 4. Register slash commands

```bash
npm run deploy
```

### 5. Jalankan bot

```bash
npm start
```

---

## Slash Commands

| Command | Deskripsi | Permission |
|---------|-----------|------------|
| `/skor match_id host guest` | Input skor ranked match | Manage Guild |
| `/skorturnamen match_id skor1 skor2` | Input skor tournament match | Manage Guild |
| `/listskor` | Lihat daftar ranked match yang aktif | Manage Guild |
| `/listturnamen` | Lihat daftar turnamen aktif | Manage Guild |
| `/listmatchturnamen tournament_id` | Lihat match pending di suatu turnamen | Manage Guild |
| `/profil [user] [username]` | Lihat statistik pemain | Semua |

### Contoh alur input skor turnamen

```
/listturnamen
→ #3 — PES Cup Summer 2026  (in_progress)

/listmatchturnamen tournament_id:3
→ #17 — BudiGanteng vs SantosoFC  (Grup A, Round 1)
→ #18 — RajaGoal vs PesKing  (Grup A, Round 1)

/skorturnamen match_id:17 skor1:3 skor2:1
→ ✅ BudiGanteng menang 3–1 vs SantosoFC!
```

---

## Cara mendapatkan Bot Token

1. Buka [Discord Developer Portal](https://discord.com/developers/applications)
2. Buat Application baru → tab **Bot** → **Reset Token**
3. Aktifkan intent: **Server Members Intent** (optional)
4. Invite bot ke server dengan scope `bot` + `applications.commands` dan permission `Send Messages`, `Embed Links`

---

## File struktur

```
discord-bot/
├── src/
│   ├── index.js              ← Entry point
│   ├── deploy-commands.js    ← Register slash commands ke Discord
│   ├── api.js                ← HTTP calls ke Laravel API
│   ├── embeds.js             ← Discord embed builders
│   └── commands/
│       ├── skor.js           ← /skor
│       ├── skorturnamen.js   ← /skorturnamen
│       ├── listskor.js       ← /listskor
│       ├── listturnamen.js   ← /listturnamen
│       ├── listmatchturnamen.js ← /listmatchturnamen
│       └── profil.js         ← /profil
├── .env.example
├── .gitignore
├── package.json
└── README.md
```
