← All N8N workflows
AI & researchCodeDiscordExecute WorkflowExecute Workflow TriggerFilter

text classifier and list message discord and removeitemsseeninpreviousexecutions remove duplicates

Configured with Discord, Execute Workflow, Execute Workflow Trigger, Filter, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
AI & modelsSpam DetectionText ClassifierMessagingGet Recent MessagesDiscordTransformOnly OnceRemove DuplicatesAI & modelsModelOpenAI Chat ModelMessagingWarn UserDiscordMessagingWarn User OnlyDiscordCodeGroup By UserCodeRoutingFor Each User...Loop Over ItemsTransformSplit OutSplit OutCodeMessage to ListCodeMessagingNotify Moderators withSend & WaitDiscordTransformFlag as SpamEdit FieldsTransformFlag as Not SpamEdit FieldsTransformMergeMergeRoutingSpam Messages OnlyFilterRoutingHas Flagged Messages?IfCodeGet Message IDsCodeMessagingDelete MessagesDiscordRoutingReceive InstructionsSwitchSubworkflowModeration SubworkflowExecute WorkflowTriggerWhen Executed byAnother WorkflowExecute Workflow TriggerRoutingNo Action TakenNo OpTriggerSchedule TriggerSchedule Trigger

Node categories in this workflow

  • AI & models
  • Messaging
  • Transform
  • Code
  • Routing
  • Subworkflow
  • Trigger

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
Spam DetectionAI & modelsText ClassifierSee node parameters
Get Recent MessagesMessagingDiscordmessage / getAll
Only OnceTransformRemove DuplicatesremoveItemsSeenInPreviousExecutions
ModelAI & modelsOpenAI Chat ModelSee node parameters
Warn UserMessagingDiscordmessage
Warn User OnlyMessagingDiscordmessage
Group By UserCodeCodeSee node parameters
For Each User...RoutingLoop Over ItemsSee node parameters
Split OutTransformSplit OutSee node parameters
Message to ListCodeCodeSee node parameters
Notify Moderators with Send & WaitMessagingDiscordmessage / sendAndWait
Flag as SpamTransformEdit FieldsSee node parameters
Flag as Not SpamTransformEdit FieldsSee node parameters
MergeTransformMergeSee node parameters
Spam Messages OnlyRoutingFilterSee node parameters
Has Flagged Messages?RoutingIfSee node parameters
Get Message IDsCodeCodeSee node parameters
Delete MessagesMessagingDiscordmessage / deleteMessage
Receive InstructionsRoutingSwitchSee node parameters
Moderation SubworkflowSubworkflowExecute WorkflowSee node parameters
When Executed by Another WorkflowTriggerExecute Workflow TriggerSee node parameters
No Action TakenRoutingNo OpSee node parameters
Schedule TriggerTriggerSchedule TriggerSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • discordBotApi
  • openAiApi

Workflow notes

1. Get Channel Messages

1. Get Channel Messages

Read more about the scheduled Trigger

The scheduled trigger is used to execute this workflow throughout the day. Depending on how busy your community is, you may want to increase the messages fetched or set shorter intervals. The "Remove Duplicates" node is used to ensure we only process new messages.

2. Group Messages By User

2. Group Messages By User

Learn more about the loop node

When dealing with nested data such as user and messages, using the loop node is a great way to ensure item references are not getting mixed up. Here, we're grouping users so that we can batch their messages and help minimise the number of notifications we need to send.

3. Spam Detection using AI-powered Text Classification

3. Spam Detection using AI-powered Text Classification

Learn more about the text classification node

In this template, our goal is to moderate spam messages and one way to do this is by using an AI text classifier. This approach uses a Reasoning LLM to determine if a message falls into a generalised criteria of spam ie. promotion. You may prefer to customise this prompt for production use-case.

5. Moderation using Human-in-the-Loop

5. Moderation using Human-in-the-Loop

Read more about n8n's human-fallback functionality

In this step, we can use the "Send and Wait for Response" operation in our Discord node to allow human moderators to decide which actions to perform on the flagged messages. There are currently 3 response types available and in this template, we'll use the custom form option which allows us to specify a dropdown list from which the moderator can select from a predefined list of actions. Using this approach, we can ensure consistency across all moderators.

6. Execute Moderation Actions

6. Execute Moderation Actions

Learn more about the Discord node

Finally, moderation actions can be executed on behalf of the moderator and thus saving them time. In the case of the delete action, the template will bulk remove the flagged messages accurately and even across multiple channels.

4. Concurrent Processing using Subworkflows

4. Concurrent Processing using Subworkflows

Learn more about Subworkflow Trigger

One issue we might come across if we have a human-in-the-loop step inside another loop is that later users will not be processed until the current user is actioned. One way of solving this is to use subworkflows. Subworkflows allow us to run our remaining workflow steps in a separate execution and with specifically the "wait for subworkflow completion" set to "off", it won't block our current loop.

Try it out

Try it out

This n8n template demonstrates how you can automate community moderation using human-in-the-loop functionality for Discord.

The use-case is for detecting and dealing with spam messages in a predefined and consistent way. Human-in-the-loop allows for a balance between overly aggressive bots and time and effort from the moderation team.

How it works

  • A scheduled trigger is used to scan the most recent messages in a Discord Channel. Messages are tagged via the "Remove Duplicates" node so they don't get processed again in the future.
  • Messages are grouped by user to allow for minimising of number of notifications sent.
  • An AI text classifier node is then used to detect for spam in each user's message.
  • When detected, a notification is sent to a moderation channel using the Send-and-wait mode for Discord. This notification comes with an n8n form and dropdown list of predefined actions to take in dealing with the spam messages. Once sent the workflow waits until a response is received.
  • Once a moderator selects an action, the workflow continues and carries out a predefined moderation action.

How to use

  • Depending on how busy your community is and subject to spammers, you may need to increase the scheduled interval.
  • Add as many or few moderation actions as required.
  • Remember to activate the workflow to get it started.

Need Help?

Join the Discord or ask in the Forum!

text classifier and list message discord and removeitemsseeninpreviousexecutions remove duplicates

text classifier and list message discord and removeitemsseeninpreviousexecutions remove duplicates

Purpose and structure

This folder contains the text classifier and list message discord and removeitemsseeninpreviousexecutions remove duplicates workflow. Its executable nodes use code, discord, executeWorkflow, executeWorkflowTrigger, filter, if, lmChatOpenAi, merge, noOp, removeDuplicates, scheduleTrigger, set, splitInBatches, splitOut, switch, textClassifier. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

When Executed by Another Workflow, Schedule Trigger

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Splitout/0816_Splitout_Code_Automation_Scheduled.json MIT; preserve source notices.

More in AI & research