Zum Inhalt

Command: !joke

Zufälliger Witz aus einer Public Joke API. Kostenlos, keine Anmeldung.

API: https://icanhazdadjoke.com/ mit Accept: application/json Patterns: Fetch URL + JSON Parse + Send Message Sub-Actions: 3

Action: [Cmd] !joke

Sub-Action 1: Fetch URL

Feld Wert
URL https://icanhazdadjoke.com/
Variable Name joke
Parse result as JSON ✅ aktiv
Headers Accept: application/json
User-Agent: AzaCraft (https://azacraft.de)

Wichtig: Ohne Accept: application/json liefert die API ein HTML-Web. Mit dem Header kommt JSON.

Response:

{
  "id": "abc123",
  "joke": "Why don't skeletons fight each other? They don't have the guts.",
  "status": 200
}

Mit JSON-Parse-Toggle wird das zu: - %joke.id% - %joke.joke% - %joke.status%

Sub-Action 2: If/Else — API down

2. If/Else: %fetchUrlStatusCode% Greater Than 299
   ├── Send Message: "@%user% Witz-API gerade nicht erreichbar."
   └── Break

Sub-Action 3: Send Message

Feld Wert
Message 😄 %joke.joke%
Send using bot account aktiv

Action-Tree

[Cmd] !joke
├── 1. Fetch URL: https://icanhazdadjoke.com/ → joke (JSON)
├── 2. If/Else: %fetchUrlStatusCode% Greater Than 299
│   ├── Send Message: "@%user% Witz-API nicht erreichbar."
│   └── Break
└── 3. Send Message: "😄 %joke.joke%"

Command-Einstellungen

Feld Wert
Name !joke
Group AzaCraft API
Commands !joke
!dadjoke
!witz
Sources Twitch Message
Global Cooldown 5
User Cooldown 30

Verwendungsbeispiele

Chat Resultat
!joke "😄 Why don't skeletons fight each other? They don't have the guts."
!dadjoke gleich

Variante: Deutscher Witz (witzapi)

Es gibt mehrere deutschsprachige Joke-APIs. Beispiel witzapi.de:

Feld Wert
URL https://witzapi.de/api/joke
Variable Name witz
Parse result as JSON ✅ aktiv

Response (kann variieren): [{"id": 1, "text": "Was ist orange ..."}] — Array! Zugriff via %witz[0].text%.

Falls die API ein Array liefert, ist Pfad-Zugriff etwas tricky. Pragmatisch: bei diesen APIs raw-String nutzen und im Send Message als ganzes posten:

Feld Wert
Message 😄 %witz%

Output ist dann das ganze JSON — nicht ideal aber funktioniert für Quick'n'Dirty.

Variante: official-joke-api

https://official-joke-api.appspot.com/random_joke liefert:

{
  "id": 100,
  "type": "general",
  "setup": "Why was the math book sad?",
  "punchline": "Because it had too many problems."
}

Pattern hier: Setup + Punchline mit Delay zeigen.

[Cmd] !joke
├── 1. Fetch URL: https://official-joke-api.appspot.com/random_joke → joke (JSON)
├── 2. Send Message: "😄 %joke.setup%"
├── 3. Delay 3000 ms
└── 4. Send Message: "💀 %joke.punchline%"

Gibt der Chat-Audience Zeit zum Mit-Denken. Klassisches Setup-Punchline-Format.

Erweiterung: Kategorien

icanhazdadjoke und ähnliche APIs unterstützen meist Filter:

  • https://icanhazdadjoke.com/search?term=cat — Witze mit "cat"

User-Input nutzen:

URL: https://icanhazdadjoke.com/search?term=$urlencode(%input0%)$

Response ist dann ein Array results[]. Bei vielen Treffern müsstest du einen random pickeln — wieder komplex ohne C#.

Häufige Fallen

  • Header Accept: application/json fehlt — API liefert HTML statt JSON. Parse-Toggle erkennt das nicht und gibt komische Werte
  • Sehr lange Witze — Twitch 500-Zeichen-Limit. Bei langer Punchline + Setup combined evtl. zu lang. Pragmatisch: ignorieren, im Notfall manuell kürzen
  • API ändert Response-Format — kostenlose APIs sind nicht stabil. Wenn %joke.joke% plötzlich nichts liefert → API-Doku prüfen

Quellen