{
  "name": "Discord AI Moderator Bot",
  "nodes": [
    {
      "parameters": {
        "event": "messageCreate",
        "options": {}
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000001",
      "name": "Discord Trigger",
      "type": "n8n-nodes-base.discord",
      "typeVersion": 2,
      "position": [
        240,
        300
      ],
      "credentials": {
        "discordBotApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "set-content",
              "name": "messageContent",
              "value": "={{ $json.content }}",
              "type": "string"
            },
            {
              "id": "set-author",
              "name": "authorId",
              "value": "={{ $json.author.id }}",
              "type": "string"
            },
            {
              "id": "set-channel",
              "name": "channelId",
              "value": "={{ $json.channel_id }}",
              "type": "string"
            },
            {
              "id": "set-msg-id",
              "name": "messageId",
              "value": "={{ $json.id }}",
              "type": "string"
            },
            {
              "id": "set-author-name",
              "name": "authorName",
              "value": "={{ $json.author.username }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000002",
      "name": "Extract Message Data",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        460,
        300
      ]
    },
    {
      "parameters": {
        "resource": "chat",
        "operation": "message",
        "model": "gpt-4o",
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "You are a content moderation AI. Analyze the following message for violations including: hate speech, harassment, spam, NSFW content, scam links, excessive caps/emojis. Respond with a JSON object: {\"violation\": true/false, \"category\": \"string or null\", \"severity\": \"low/medium/high or null\", \"reason\": \"brief explanation\"}. Only output the JSON, nothing else."
            },
            {
              "role": "user",
              "content": "={{ $json.messageContent }}"
            }
          ]
        },
        "options": {
          "temperature": 0.1,
          "maxTokens": 200,
          "response_format": {
            "type": "json_object"
          }
        }
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000003",
      "name": "OpenAI Moderate",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.6,
      "position": [
        680,
        300
      ],
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "check-violation",
              "leftValue": "={{ JSON.parse($json.message.content).violation }}",
              "rightValue": true,
              "operator": {
                "type": "boolean",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000004",
      "name": "IF Violation Detected",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [
        900,
        300
      ]
    },
    {
      "parameters": {
        "method": "DELETE",
        "url": "=https://discord.com/api/v10/channels/{{ $('Extract Message Data').item.json.channelId }}/messages/{{ $('Extract Message Data').item.json.messageId }}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "options": {}
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000005",
      "name": "Delete Violating Message",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1120,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "=https://discord.com/api/v10/channels/{{ $('Extract Message Data').item.json.channelId }}/messages",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "content",
              "value": "=\u26a0\ufe0f <@{{ $('Extract Message Data').item.json.authorId }}> Your message was removed for violating server rules ({{ JSON.parse($('OpenAI Moderate').item.json.message.content).category }}). Please review the community guidelines."
            }
          ]
        },
        "options": {}
      },
      "id": "c3d4e5f6-3333-4000-8000-000000000006",
      "name": "Send Warning",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1340,
        200
      ],
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "connections": {
    "Discord Trigger": {
      "main": [
        [
          {
            "node": "Extract Message Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract Message Data": {
      "main": [
        [
          {
            "node": "OpenAI Moderate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Moderate": {
      "main": [
        [
          {
            "node": "IF Violation Detected",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "IF Violation Detected": {
      "main": [
        [
          {
            "node": "Delete Violating Message",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Delete Violating Message": {
      "main": [
        [
          {
            "node": "Send Warning",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null
}