8
n8n 中文网amn8n.com

自动化 Discord 垃圾信息审核

高级

这是一个AI, IT Ops领域的自动化工作流,包含 30 个节点。主要使用 If, Set, Code, Merge, Filter 等节点,结合人工智能技术实现智能自动化。 结合 AI 和人机协作的自动化 Discord 垃圾信息审核

前置要求
  • Discord Bot Token 或 Webhook
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "meta": {
    "instanceId": "408f9fb9940c3cb18ffdef0e0150fe342d6e655c3a9fac21f0f644e8bedabcd9",
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "59b7eed3-8622-4722-b93f-f225cc0aa4e0",
      "name": "垃圾信息检测",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        260,
        100
      ],
      "parameters": {
        "options": {},
        "inputText": "={{ $json.content }}",
        "categories": {
          "categories": [
            {
              "category": "is_spam",
              "description": "This text is a promotion, sales pitch or likely spam message to get members to visit another site."
            },
            {
              "category": "is_not_spam",
              "description": "This text is not spam."
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "74420874-d831-4ff0-a8f4-e7c3b6551c57",
      "name": "获取最近消息",
      "type": "n8n-nodes-base.discord",
      "position": [
        -1020,
        40
      ],
      "webhookId": "7aa72e1f-06f4-4fe8-82ec-ad0e87a5b6b9",
      "parameters": {
        "guildId": {
          "__rl": true,
          "mode": "id",
          "value": "123456789"
        },
        "options": {
          "simplify": true
        },
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "1248678443432808512",
          "cachedResultUrl": "https://discord.com/channels/1248678443432808509/1248678443432808512",
          "cachedResultName": "general"
        },
        "operation": "getAll"
      },
      "credentials": {
        "discordBotApi": {
          "id": "YUwD52E3oHsSUWdW",
          "name": "Discord Bot account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "6db26c7e-f1eb-45b8-a444-01270fab157f",
      "name": "仅一次",
      "type": "n8n-nodes-base.removeDuplicates",
      "position": [
        -820,
        40
      ],
      "parameters": {
        "options": {
          "historySize": 100
        },
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.id }}"
      },
      "typeVersion": 2
    },
    {
      "id": "36923da1-5ebc-40fc-9780-74845ff2b268",
      "name": "模型",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        240,
        260
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "o3-mini",
          "cachedResultName": "o3-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "id": "8gccIjcuf3gvaoEr",
          "name": "OpenAi account"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "af01bb60-fdef-4fa1-bf33-1862a18ebc99",
      "name": "警告用户",
      "type": "n8n-nodes-base.discord",
      "position": [
        2880,
        20
      ],
      "webhookId": "88bdd468-8eb9-41b8-b017-1deec91c9498",
      "parameters": {
        "sendTo": "user",
        "userId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Executed by Another Workflow').first().json.author.id }}"
        },
        "content": "=Warning: Please do not spam our channels\nYour message was deleted to be in violation of our community terms & conditions and was subsequently deleted.\n\nFurther violations will result in a ban.\n\nIf you think this is a mistake, please message the moderation team.",
        "guildId": {
          "__rl": true,
          "mode": "id",
          "value": "123456789"
        },
        "options": {},
        "resource": "message"
      },
      "credentials": {
        "discordBotApi": {
          "id": "YUwD52E3oHsSUWdW",
          "name": "Discord Bot account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "04e9f167-f816-4056-813a-3168dc22f209",
      "name": "仅警告用户",
      "type": "n8n-nodes-base.discord",
      "position": [
        2540,
        180
      ],
      "webhookId": "88bdd468-8eb9-41b8-b017-1deec91c9498",
      "parameters": {
        "sendTo": "user",
        "userId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('When Executed by Another Workflow').first().json.author.id }}"
        },
        "content": "=Warning: Please do not spam our channels\nYour message was flagged to be in violation of our community terms & conditions. Please consider other members before posting.\n\nFurther violations will result in a ban.\n\nIf you think this is a mistake, please message the moderation team.",
        "guildId": {
          "__rl": true,
          "mode": "id",
          "value": "123456789"
        },
        "options": {},
        "resource": "message"
      },
      "credentials": {
        "discordBotApi": {
          "id": "YUwD52E3oHsSUWdW",
          "name": "Discord Bot account"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "41240c95-c5c1-4ac2-81e7-782ff8f3511b",
      "name": "按用户分组",
      "type": "n8n-nodes-base.code",
      "position": [
        -540,
        100
      ],
      "parameters": {
        "jsCode": "const groupByUser = {};\n\nfor (const item of $input.all()) {\n  if (!groupByUser[item.json.author.id]) {\n    groupByUser[item.json.author.id] = [];\n  }\n  groupByUser[item.json.author.id].push(item.json);\n}\n\nreturn { json : { groupByUser } };"
      },
      "typeVersion": 2
    },
    {
      "id": "03d56683-c307-455d-bd03-84107d30f328",
      "name": "对于每个用户...",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -160,
        100
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "e7eb71a8-cfe5-4e3b-81c1-66ea18cc55ec",
      "name": "拆分输出",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -360,
        100
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "groupByUser"
      },
      "typeVersion": 1
    },
    {
      "id": "b74a7092-2b51-452b-bf29-6620969b3efb",
      "name": "消息发送到列表",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        100
      ],
      "parameters": {
        "jsCode": "const messages = $input.first().json;\nreturn Object.keys(messages).map(key => messages[key]);"
      },
      "typeVersion": 2
    },
    {
      "id": "762e3a5e-e013-4ca3-a2a9-cf7d5b0dd3f4",
      "name": "通过发送并等待通知版主",
      "type": "n8n-nodes-base.discord",
      "position": [
        1980,
        180
      ],
      "webhookId": "644a85f3-5add-4321-9d8a-bcc4acfa33f1",
      "parameters": {
        "guildId": {
          "__rl": true,
          "mode": "id",
          "value": "123456789"
        },
        "message": "=**Spam Detected**\nUser: @{{ $json.author.username }}\nMessage:\n{{\n$input.all().map(item =>\n  `* [${DateTime.fromISO(item.json.timestamp).format('yyyy-MM-dd @ hh:mm')}] ${item.json.content}`).join('\\n')\n}}",
        "options": {},
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "=_moderation"
        },
        "operation": "sendAndWait",
        "formFields": {
          "values": [
            {
              "fieldType": "dropdown",
              "fieldLabel": "Action",
              "fieldOptions": {
                "values": [
                  {
                    "option": "Delete Message and Warn User"
                  },
                  {
                    "option": "Do nothing and Warn User"
                  },
                  {
                    "option": "Do nothing"
                  }
                ]
              },
              "requiredField": true
            }
          ]
        },
        "responseType": "customForm"
      },
      "credentials": {
        "discordBotApi": {
          "id": "YUwD52E3oHsSUWdW",
          "name": "Discord Bot account"
        }
      },
      "executeOnce": true,
      "typeVersion": 2
    },
    {
      "id": "f35bc6b0-855c-451b-aee7-e2af4e268893",
      "name": "标记为垃圾信息",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e1eddfbe-c32d-4a3b-9660-07800f52f4c4",
              "name": "is_spam",
              "type": "boolean",
              "value": true
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4
    },
    {
      "id": "f77a0101-d209-4d3c-ab4a-405579a1f539",
      "name": "标记为非垃圾信息",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        200
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "e1eddfbe-c32d-4a3b-9660-07800f52f4c4",
              "name": "is_spam",
              "type": "boolean",
              "value": false
            }
          ]
        },
        "includeOtherFields": true
      },
      "typeVersion": 3.4,
      "alwaysOutputData": true
    },
    {
      "id": "eefe79e2-603f-4f12-a385-fab4b8bdbc65",
      "name": "合并",
      "type": "n8n-nodes-base.merge",
      "position": [
        800,
        100
      ],
      "parameters": {},
      "typeVersion": 3
    },
    {
      "id": "f7d6cccc-0d4a-4353-bc30-9a760196361f",
      "name": "仅垃圾信息",
      "type": "n8n-nodes-base.filter",
      "position": [
        1060,
        100
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f1dd7aa3-4215-47b5-830c-0d8d17e97c17",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              },
              "leftValue": "={{ $json.is_spam }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2,
      "alwaysOutputData": true
    },
    {
      "id": "7b4257b9-a5d3-4542-b4e2-563bf5634aa5",
      "name": "有标记的消息吗?",
      "type": "n8n-nodes-base.if",
      "position": [
        1240,
        180
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f085cf62-e82d-4a15-806b-4a740e3b119c",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "0282a8bf-ab06-427f-b58b-83131205b26c",
      "name": "获取消息 ID",
      "type": "n8n-nodes-base.code",
      "position": [
        2540,
        20
      ],
      "parameters": {
        "jsCode": "return $('When Executed by Another Workflow').all().map(item => ({ json: {\n  id: item.json.id,\n  channel_id: item.json.channel_id\n}}))"
      },
      "typeVersion": 2
    },
    {
      "id": "fc43a315-6b81-4d93-8e11-7955b7650b94",
      "name": "删除消息",
      "type": "n8n-nodes-base.discord",
      "position": [
        2720,
        20
      ],
      "webhookId": "6fa8bb1c-c5b7-4498-af63-dbe43691e602",
      "parameters": {
        "guildId": {
          "__rl": true,
          "mode": "id",
          "value": "123456789"
        },
        "resource": "message",
        "channelId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $json.channel_id }}"
        },
        "messageId": "={{ $json.id }}",
        "operation": "deleteMessage"
      },
      "credentials": {
        "discordBotApi": {
          "id": "YUwD52E3oHsSUWdW",
          "name": "Discord Bot account"
        }
      },
      "executeOnce": false,
      "typeVersion": 2
    },
    {
      "id": "3868754b-26df-4f06-b27b-dba3959cb365",
      "name": "接收指令",
      "type": "n8n-nodes-base.switch",
      "position": [
        2180,
        180
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Delete & Warn",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "c9a82ef5-49f7-4196-9ee3-977d34bd1ec9",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.Action }}",
                    "rightValue": "Delete Message and Warn User"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Warn User Only",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "0e0d56da-bae0-4624-b712-fa44413eb17f",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.Action }}",
                    "rightValue": "Do nothing and Warn User"
                  }
                ]
              },
              "renameOutput": true
            },
            {
              "outputKey": "Do nothing",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "2f85cdf6-db7b-4e30-9577-20ddee437807",
                    "operator": {
                      "name": "filter.operator.equals",
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.data.Action }}",
                    "rightValue": "Do nothing"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "27ea2dd8-07f0-438a-bee8-8c4a6ee7b5f7",
      "name": "便签",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 620,
        "height": 520,
        "content": "## 1. 获取频道消息"
      },
      "typeVersion": 1
    },
    {
      "id": "66e770ab-4eaa-40b6-be73-c36bad254c2a",
      "name": "便签1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 640,
        "height": 520,
        "content": "## 2. 按用户分组消息"
      },
      "typeVersion": 1
    },
    {
      "id": "963074bf-91e5-4a47-886d-0dbcbbba8fc4",
      "name": "便签2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 960,
        "height": 620,
        "content": "## 3. 使用 AI 驱动的文本分类进行垃圾信息检测"
      },
      "typeVersion": 1
    },
    {
      "id": "0cbcfe9d-7f66-423c-b930-a3c700636bd8",
      "name": "便签3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 740,
        "height": 620,
        "content": "## 5. 使用人工介入进行审核"
      },
      "typeVersion": 1
    },
    {
      "id": "c808c1a9-818e-4652-a92b-b6be1cb12706",
      "name": "便签4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 660,
        "height": 680,
        "content": "## 6. 执行审核操作"
      },
      "typeVersion": 1
    },
    {
      "id": "c08416cb-a477-4ccc-b682-85c35d9c2cd6",
      "name": "审核子工作流",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1460,
        200
      ],
      "parameters": {
        "options": {
          "waitForSubWorkflow": false
        },
        "workflowId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $workflow.id }}"
        },
        "workflowInputs": {
          "value": {},
          "schema": [],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": true
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "f130b908-1653-4cb4-a72d-ae539c7a08dc",
      "name": "便签5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 660,
        "height": 620,
        "content": "## 4. 使用子工作流进行并发处理"
      },
      "typeVersion": 1
    },
    {
      "id": "dc5e79f1-1ed9-4171-a787-a6b9dfee71f2",
      "name": "当由另一个工作流执行时",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        1780,
        180
      ],
      "parameters": {
        "inputSource": "passthrough"
      },
      "typeVersion": 1.1
    },
    {
      "id": "df28cb07-a4fe-4edf-afd0-18f4fa12521d",
      "name": "便签6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1700,
        -580
      ],
      "parameters": {
        "width": 380,
        "height": 940,
        "content": "## 试试看"
      },
      "typeVersion": 1
    },
    {
      "id": "a437d4f3-af31-4677-b853-99832ff6c051",
      "name": "未采取任何操作",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2540,
        340
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "82a5b512-296b-4ad7-aa50-2f34ff2cf681",
      "name": "计划触发器",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1220,
        40
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours"
            }
          ]
        }
      },
      "typeVersion": 1.2
    }
  ],
  "pinData": {},
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Spam Messages Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model": {
      "ai_languageModel": [
        [
          {
            "node": "Spam Detection",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Only Once": {
      "main": [
        [
          {
            "node": "Group By User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Warn User": {
      "main": [
        []
      ]
    },
    "Flag as Spam": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group By User": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spam Detection": {
      "main": [
        [
          {
            "node": "Flag as Spam",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Flag as Not Spam",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Warn User Only": {
      "main": [
        []
      ]
    },
    "Delete Messages": {
      "main": [
        [
          {
            "node": "Warn User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Message IDs": {
      "main": [
        [
          {
            "node": "Delete Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message to List": {
      "main": [
        [
          {
            "node": "Spam Detection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flag as Not Spam": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "For Each User...": {
      "main": [
        [],
        [
          {
            "node": "Message to List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Recent Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spam Messages Only": {
      "main": [
        [
          {
            "node": "Has Flagged Messages?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent Messages": {
      "main": [
        [
          {
            "node": "Only Once",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Instructions": {
      "main": [
        [
          {
            "node": "Get Message IDs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Warn User Only",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Action Taken",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Flagged Messages?": {
      "main": [
        [
          {
            "node": "Moderation Subworkflow",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Moderation Subworkflow": {
      "main": [
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Notify Moderators with Send & Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Moderators with Send & Wait": {
      "main": [
        [
          {
            "node": "Receive Instructions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

高级 - 人工智能, IT 运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
高级
节点数量30
分类2
节点类型17
难度说明

适合高级用户,包含 16+ 个节点的复杂工作流

作者
Jimleuk

Jimleuk

@jimleuk

Freelance consultant based in the UK specialising in AI-powered automations. I work with select clients tackling their most challenging projects. For business enquiries, send me an email at hello@jimle.uk LinkedIn: https://www.linkedin.com/in/jimleuk/ X/Twitter: https://x.com/jimle_uk

外部链接
在 n8n.io 查看

分享此工作流