- discord.js v14 Bot mit Slash-Command-Registry (Guild oder global) - Konfiguration über .env mit Validierung (config.js) - Dockerfile + docker-compose.yml für Portainer-Deployment - README mit Schritt-für-Schritt-Anleitung (Discord Developer Portal) Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
115 lines
3.3 KiB
Markdown
115 lines
3.3 KiB
Markdown
# EcoBot
|
|
|
|
Discord-Bot + Webinterface für die EcoGame-Community.
|
|
|
|
**Features (Roadmap):**
|
|
1. ✅ Bot online + `/ping` Slash-Command
|
|
2. ⬜ Commit-Feed: Gitea-Push-Webhooks → Discord-Embeds + SQLite-Archiv
|
|
3. ⬜ Devlog-Archiv: tägliche Devlogs archivieren
|
|
4. ⬜ Webinterface: Discord-Login, Devlog- & Commit-Seiten
|
|
|
|
**Stack:** Node.js 20+, discord.js v14, Fastify (ab Feature 2), React (ab Feature 4), SQLite, Docker
|
|
|
|
---
|
|
|
|
## Setup: Discord-App anlegen (einmalig)
|
|
|
|
### 1. App erstellen
|
|
1. Öffne das [Discord Developer Portal](https://discord.com/developers/applications)
|
|
2. **New Application** → Name: `EcoBot` → Create
|
|
3. Unter **General Information** die **Application ID** kopieren
|
|
→ das ist `DISCORD_CLIENT_ID`
|
|
|
|
### 2. Bot-Token holen
|
|
1. Linke Seitenleiste → **Bot**
|
|
2. **Reset Token** → Token kopieren → das ist `DISCORD_TOKEN`
|
|
⚠️ Der Token wird nur einmal angezeigt — direkt in die `.env` eintragen!
|
|
3. Auf der Bot-Seite weiter unten: **Message Content Intent** aktivieren
|
|
(brauchen wir ab Feature 3 zum Lesen der Devlog-Nachrichten)
|
|
|
|
### 3. Bot auf den Server einladen
|
|
1. Linke Seitenleiste → **OAuth2** → **URL Generator**
|
|
2. Scopes ankreuzen: `bot` und `applications.commands`
|
|
3. Bot Permissions ankreuzen:
|
|
- **Send Messages**
|
|
- **Embed Links**
|
|
- **Read Message History**
|
|
4. Generierte URL unten kopieren, im Browser öffnen, deinen Server auswählen → **Autorisieren**
|
|
|
|
### 4. Server-ID holen (für sofortige Slash-Commands)
|
|
1. In Discord: Einstellungen → Erweitert → **Entwicklermodus** aktivieren
|
|
2. Rechtsklick auf deinen Server → **Server-ID kopieren**
|
|
→ das ist `DISCORD_GUILD_ID`
|
|
|
|
### 5. .env anlegen
|
|
```
|
|
cp .env.example .env
|
|
```
|
|
Dann die drei Werte eintragen. Die `.env` ist in `.gitignore` und landet nie im Repo.
|
|
|
|
---
|
|
|
|
## Lokal starten (Entwicklung)
|
|
|
|
```
|
|
npm install
|
|
npm run dev
|
|
```
|
|
|
|
Erwartete Ausgabe:
|
|
```
|
|
[bot] Eingeloggt als EcoBot#1234
|
|
[bot] 1 Slash-Command(s) registriert (Guild)
|
|
```
|
|
|
|
Dann in Discord: `/ping` → Bot antwortet mit Latenz. 🎉
|
|
|
|
---
|
|
|
|
## Deployment (Docker / Portainer)
|
|
|
|
### Variante A: Portainer-Stack aus Git (empfohlen)
|
|
1. Portainer → **Stacks** → **Add stack**
|
|
2. **Repository** wählen:
|
|
- URL: `https://git.d4rkst3r.de/D4rkst3r/ecobot.git`
|
|
- Compose path: `docker-compose.yml`
|
|
3. Unter **Environment variables** die drei Werte aus der `.env` eintragen
|
|
(`DISCORD_TOKEN`, `DISCORD_CLIENT_ID`, `DISCORD_GUILD_ID`)
|
|
— alternativ `env_file` weglassen und die Variablen direkt im Stack setzen
|
|
4. **Deploy the stack**
|
|
|
|
### Variante B: Manuell auf dem Server
|
|
```
|
|
git clone git@gitea:D4rkst3r/ecobot.git
|
|
cd ecobot
|
|
cp .env.example .env # Werte eintragen
|
|
docker compose up -d --build
|
|
```
|
|
|
|
Logs prüfen:
|
|
```
|
|
docker logs -f ecobot
|
|
```
|
|
|
|
---
|
|
|
|
## Projektstruktur
|
|
|
|
```
|
|
ecobot/
|
|
├── src/
|
|
│ ├── index.js # Einstiegspunkt
|
|
│ ├── config.js # Env-Konfiguration mit Validierung
|
|
│ └── bot/
|
|
│ ├── client.js # Discord-Client, Command-Registry, Interactions
|
|
│ └── commands/
|
|
│ └── ping.js # /ping — Lebenszeichen
|
|
├── .env.example # Vorlage für Secrets (nach .env kopieren)
|
|
├── Dockerfile
|
|
├── docker-compose.yml
|
|
└── README.md
|
|
```
|
|
|
|
Neue Slash-Commands: Datei in `src/bot/commands/` anlegen (exportiert `data` + `execute`)
|
|
und in `src/bot/client.js` bei `commandModules` eintragen.
|