This workflow corresponds to n8n.io template #5816 — we link there as the canonical source.
This workflow follows the Agent → OpenAI Chat recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "1a8503cb-7d8f-4160-b9aa-bfe5c75f02e0",
"name": "Calculator",
"type": "@n8n/n8n-nodes-langchain.toolCalculator",
"position": [
1000,
520
],
"parameters": {},
"typeVersion": 1
},
{
"id": "8dab1d16-0d0d-47fe-9675-017827a0188c",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-640,
40
],
"parameters": {
"width": 953.4544277976706,
"content": "## .env for Discord bot\n```md\nTOKEN=your-bot-token-here\nWEBHOOK_URL=https://your-domain.tld/webhook/getmessage\n```"
},
"typeVersion": 1
},
{
"id": "b83c3a70-fe5e-4f90-8177-e6fbefc1af2a",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
-640,
1220
],
"parameters": {
"width": 949,
"height": 100,
"content": "## requirements.txt,txt\ndiscord\npython-dotenv"
},
"typeVersion": 1
},
{
"id": "8c4b3445-005e-4418-9ad0-e89c53b077b4",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
-640,
220
],
"parameters": {
"width": 953.7499545009089,
"height": 974.8320906053484,
"content": "## Discord Bot Code\n\n```py\nimport discord\nimport requests\nimport json\nimport os\nfrom dotenv import load_dotenv\n\n# Load environment variables from .env file\nload_dotenv()\nTOKEN = os.getenv(\"TOKEN\")\nWEBHOOK_URL = os.getenv(\"WEBHOOK_URL\")\n\n# Bot Configuration\nLISTEN_CHANNELS = [123456789012345678] # Replace with your target channel IDs\n\n# Intents setup\nintents = discord.Intents.default()\nintents.messages = True # Enable message event\nintents.guilds = True\nintents.message_content = True # Required to read messages\n\nclient = discord.Client(intents=intents)\n\n@client.event\nasync def on_ready():\n print(f'Logged in as {client.user}')\n\n@client.event\nasync def on_message(message):\n if message.author == client.user:\n return # Ignore bot's own messages\n \n if message.channel.id in LISTEN_CHANNELS:\n try:\n fetched_message = await message.channel.fetch_message(message.id) # Ensure correct fetching\n payload = {\n \"channel_id\": str(fetched_message.channel.id), # Ensure it's string\n \"chat_message\": fetched_message.content,\n \"timestamp\": str(fetched_message.created_at), # Ensure proper formatting\n \"message_id\": str(fetched_message.id), # Ensure ID is a string\n \"user_id\": str(fetched_message.author.id) # Ensure user ID is also string\n }\n \n headers = {'Content-Type': 'application/json'}\n response = requests.post(WEBHOOK_URL, data=json.dumps(payload), headers=headers)\n \n if response.status_code == 200:\n print(f\"Message sent successfully: {payload}\")\n else:\n print(f\"Failed to send message: {response.status_code}, Response: {response.text}\")\n except Exception as e:\n print(f\"Error fetching message: {e}\")\n\nclient.run(TOKEN)\n\n```"
},
"typeVersion": 1
},
{
"id": "1187dd59-d4d9-4916-8b91-49e5e0756cc1",
"name": "Response fromAI",
"type": "n8n-nodes-base.discord",
"position": [
1120,
220
],
"parameters": {
"content": "={{ $json.output }}",
"guildId": {
"__rl": true,
"mode": "list",
"value": "697416344865472593",
"cachedResultUrl": "https://discord.com/channels/697416344865472593",
"cachedResultName": "server"
},
"options": {
"message_reference": "={{ $('Get Discord Messages').item.json.body.message_id }}"
},
"resource": "message",
"channelId": {
"__rl": true,
"mode": "list",
"value": "1336754177824653423",
"cachedResultUrl": "https://discord.com/channels/697416344865472593/1336754177824653423",
"cachedResultName": "assistant"
}
},
"credentials": {
"discordBotApi": {
"name": "<your credential>"
}
},
"typeVersion": 2
},
{
"id": "51199d60-0549-43a6-affd-e0056fba36f5",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
420,
120
],
"parameters": {
"color": 4,
"width": 220,
"height": 260,
"content": "Get the Production Webhook URL for .env"
},
"typeVersion": 1
},
{
"id": "af7b7213-e586-4ca0-9caf-38ba91a74092",
"name": "OpenAI -4o-mini ",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
640,
520
],
"parameters": {
"model": "gpt-4o-mini-2024-07-18",
"options": {
"maxTokens": 2000
}
},
"credentials": {
"openAiApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "0788c61b-ae58-446a-a5fe-06bf15b2c2f3",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1020,
120
],
"parameters": {
"color": 6,
"width": 300,
"height": 260,
"content": "Change the Channel According to you. \n( Recommend to make it Private if you are using it for personal Chat )"
},
"typeVersion": 1
},
{
"id": "6c2cc2e2-0123-45ac-ae8c-2f6f2d294c14",
"name": "Get Discord Messages",
"type": "n8n-nodes-base.webhook",
"position": [
480,
220
],
"parameters": {
"path": "getmessage",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 2
},
{
"id": "874ba5fd-2d34-4621-a147-0a3f161fb9a1",
"name": "Message History",
"type": "@n8n/n8n-nodes-langchain.memoryRedisChat",
"position": [
800,
520
],
"parameters": {
"sessionKey": "={{ $('Get Discord Messages').item.json.body.user_id}}",
"sessionIdType": "customKey"
},
"credentials": {
"redis": {
"name": "<your credential>"
}
},
"typeVersion": 1.4
},
{
"id": "2f228d84-3ee6-4050-a7f3-3d0e6a70c4fc",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
940,
480
],
"parameters": {
"width": 280,
"height": 220,
"content": "\n\n\n\n\n\n\n\n\n\n\n\nAdd additional necessary Tools based on you requirements."
},
"typeVersion": 1
},
{
"id": "b2dd03bf-e52e-4046-a94b-1020ccc3709d",
"name": "Chat Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
700,
220
],
"parameters": {
"text": "={{ $json.body.chat_message }} \n\nKeep the Reply Max and under 1800 characters.",
"agent": "conversationalAgent",
"options": {},
"promptType": "define"
},
"typeVersion": 1.6
}
],
"connections": {
"Calculator": {
"ai_tool": [
[
{
"node": "Chat Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Chat Agent": {
"main": [
[
{
"node": "Response fromAI",
"type": "main",
"index": 0
}
]
]
},
"Message History": {
"ai_memory": [
[
{
"node": "Chat Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"OpenAI -4o-mini ": {
"ai_languageModel": [
[
{
"node": "Chat Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Get Discord Messages": {
"main": [
[
{
"node": "Chat Agent",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
discordBotApiopenAiApiredis
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Description: This n8n workflow automates a Discord bot to fetch messages from a specified channel and send AI-generated responses in threads. It ensures smooth message processing and interaction, making it ideal for managing community discussions, customer support, or AI-based…
Source: https://n8n.io/workflows/5816/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Agente_Aline(carlos). Uses lmChatOpenAi, toolCalculator, agent, googleCalendarTool. Webhook trigger; 21 nodes.
friday. Uses lmChatOpenAi, outputParserStructured, toolCalculator, memoryRedisChat. Webhook trigger; 14 nodes.
jarvis. Uses agent, lmChatOpenAi, outputParserStructured, toolWorkflow. Webhook trigger; 13 nodes.
Flux. Uses lmChatOpenAi, agent, googleGemini, httpRequest. Webhook trigger; 67 nodes.
Agente de Agendamento YT. Uses googleSheets, n8n-nodes-evolution-api, openAi, redis. Webhook trigger; 26 nodes.