Discord Chatbot using Gemini 2.0 Flash with Conversational Memory - n8n Workflow

Deploy a robust, stateful Discord chatbot using this advanced n8n workflow template. Leverage the n8n node system with Gemini 2.0 Flash and LangChain for real-time, context-aware AI interactions.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Users looking to deploy a sophisticated, custom AI assistant on Discord.
Developers needing an n8n template for integrating LangChain and advanced conversational memory.
Content creators (like 'Presting Podcasts' mentioned in the system message) wanting to automate responses based on specific knowledge bases.
Automation specialists seeking expert examples of complex n8n node configurations and webhook response handling.

Overview

This n8n workflow solves the challenge of creating a dynamic, memory-enabled chatbot accessible directly through Discord. By utilizing a public n8n trigger, it seamlessly handles incoming chat messages from an external Discord application (or bot handler). The core value lies in the integration of the LangChain Agent n8n node, which uses Google's Gemini 2.0 Flash model and a dedicated conversational memory store. This ensures that the bot remembers the context of previous messages from the same user, leading to natural and coherent conversations. This specialized n8n template demonstrates how to structure complex AI logic and correctly format the output for external services, making it a powerful foundation for any custom n8n automation project. Setting up this n8n workflow is a rapid way to deploy sophisticated AI capabilities.

How it Works

This powerful n8n workflow executes the following steps:


  1. Webhook Trigger: The process begins with the n8n trigger, which is an HTTP Webhook configured to listen for POST requests. This webhook receives data from Discord, including the userId, userName, and the question asked by the user.

  2. AI Agent Orchestration: The incoming data immediately flows into the Discord AI Response Agent n8n node (a LangChain Agent). This node constructs the prompt, incorporating the user's name and question, and enforces a specific system message instructing the AI to act as a helpful assistant and remember to tag the user (@insertusername) in the response.

  3. Conversational Memory: The agent connects to the Simple Memory n8n node (LangChain Memory Buffer Window). This node uses the unique userId from the initial webhook body to maintain a distinct, ongoing conversation history for that specific user. This is crucial for building a stateful n8n workflow.

  4. LLM Generation: The agent passes the full context (system prompt + current message + history from memory) to the Google Gemini Chat Model n8n node, which generates the response using the efficient models/gemini-2.0-flash model.

  5. Output Formatting: The AI's output is received by the correctNaming Code n8n node. Since the output format must be exact for Discord integration, this n8n node extracts the raw AI text and wraps it into a standardized JSON structure: {"answer": "..."}.

  6. Response: Finally, the Respond to Webhook n8n node sends the standardized, AI-generated answer back to the originating Discord service, completing the asynchronous conversation loop defined by this n8n workflow.

Installation Guide

To install and utilize this n8n workflow, follow these instructions:


  1. Import the JSON: Copy the provided n8n workflow JSON and paste it directly into your n8n instance's canvas using the 'New' -> 'Import from JSON' option.

  2. Configure Credentials:

* Google Gemini Chat Model: You will need to set up credentials for Google AI (or Google Palm API, depending on your n8n instance version) to utilize the Gemini 2.0 Flash model. Ensure this credential is selected in the 'Google Gemini Chat Model' n8n node.

  1. Activate the Webhook: After importing, click the 'Webhook' n8n node and note the Test or Production URL path (/b0631bec-9ccc-4eb8-b143-d73609b213c7).

  2. External Setup (Discord): You must configure your external Discord bot handler or custom Discord application to send incoming chat messages (containing userId, userName, and question) as a POST request to the Webhook URL path provided by this n8n trigger.

  3. Activate the Workflow: Set the n8n workflow to 'Active' to start listening for Discord messages.

Node Details

Webhook (n8n trigger):
Function: Serves as the initial n8n trigger, receiving a POST request containing user information and the chat question from Discord.
Key Configuration: Path is set to a unique identifier; Response Mode is set to 'Response Node' to wait for the final AI output.
Discord AI Response Agent (LangChain Agent n8n node):
Function: The central orchestration point. It structures the full prompt, incorporates conversational history, and manages the call to the LLM.
Key Configuration: System message defines the bot's persona and includes strict instructions for formatting the output (starting with @insertusername). Input text dynamically pulls user data from the webhook payload.
Simple Memory (LangChain Memory Buffer Window n8n node):
Function: Provides stateful memory for the chatbot. It stores recent conversation history, allowing the AI to maintain context.
Key Configuration: Session Key is dynamically set using ={{ $json.body.userId }} to ensure each user maintains their own unique chat thread, a key feature of this n8n workflow.
Google Gemini Chat Model (LangChain LLM n8n node):
Function: Executes the AI generation using the specified model (models/gemini-2.0-flash).
Key Configuration: Uses predefined credentials to access the Google AI API.
correctNaming (Code n8n node):
Function: Essential post-processing n8n node that transforms the raw output of the AI into the specific JSON format expected by the external Discord service ({"answer": "..."}).
Respond to Webhook (n8n node):
Function: Sends the final, formatted AI response back to the system that initiated the n8n trigger call, closing the interaction loop.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
JPres
JPres

Featured*