A Discord bot that responds to mentions by sending messages to n8n workflows and returning the responses. Connects Discord conversations with custom automations, APIs, and AI services through n8n. Full guide on: Discord Bot Summary Overview The Discord bot listens for mentions, forwards questions to an n8n workflow, processes responses, and replies in Discord. This workflow is intended for all Discord users who want to offer AI interactions with their respective channels. What do you need? - Yo

A Discord bot that responds to mentions by sending messages to n8n workflows and returning the responses. Connects Discord conversations with custom automations, APIs, and AI services through n8n. Full guide on: Discord Bot Summary Overview The Discord bot listens for mentions, forwards questions to an n8n workflow, processes responses, and replies in Discord. This workflow is intended for all Discord users who want to offer AI interactions with their respective channels. What do you need? - You need a Discord account as well as a Google Cloud Project Key Features 1. Listens for Mentions - The bot monitors Discord channels for messages that mention it. - Optional Configuration: Can be set to respond only in a specific channel. 2. Forwards Questions to n8n - When a user mentions the bot and asks a question: - The bot extracts the question. - Sends the question, along with channel and user information, to an n8n webhook URL. 3. Processes Data in n8n - The n8n workflow receives the question and can: - Interact with AI services (e.g., generating responses). - Access databases or external APIs. - Perform custom logic. - n8n formats the response and sends it back to the bot. 4. Replies to Discord with n8n's Response - The bot receives the response from n8n. - It replies to the user's message in the Discord channel with the answer. - Long Responses: Handles responses exceeding Discord's 2000-character limit by chunking them into multiple messages. 5. Error Handling - Includes error handling for: - Issues with n8n communication. - Response formatting problems. - Manages cases where: - No question is asked. - An invalid response is received from n8n. 6. Typing Indicator - While waiting for n8n's response, the bot sends a "typing..." indicator to the Discord channel. 7. Status Update - For lengthy n8n processes, the bot sends a message to the Discord channel to inform the user that it is still processing their request. Step-by-Step Setup Guide as per Github Instructions Key Takeaways - You’ll configure an n8n webhook to receive Discord messages, process them with your workflow, and respond. - You’ll set up a Discord application and bot, grant the right permissions/intents, and invite it to your server. - You’ll prepare your server environment (Node.js), scaffold the project, and wire up environment variables. - You’ll implement message‐chunking, “typing…” indicators, and robust error handling in your bot code. - You’ll deploy with PM2 for persistence and know how to test and troubleshoot common issues. --- 1. n8n: Create & Expose Your Webhook 1. New Workflow - Log into your n8n instance. - Click Create Workflow (➕), name it e.g. Discord Bot Handler. 2. Webhook Trigger - Add a node (➕) → search Webhook. - Set: - Authentication: None (or your choice) - HTTP Method: POST - Path: e.g. /discord-bot - Click Execute Node to activate. 3. Copy Webhook URL - After execution, copy the Production Webhook URL. - You’ll paste this into your bot’s .env. 4. Build Your Logic - Chain additional nodes (AI, database lookups, etc.) as required. 5. Format the JSON Response - Insert a Function node before the end: 6. Respond to Webhook - Add Respond to Webhook as the final node. - Point it at your Function node’s output (with the answer field). 7. Activate - Toggle Active in the top‐right and Save. --- 2. Discord Developer Portal: App & Bot 1. New Application - Visit the Discord Developer Portal. - Click New Application, name it. - Go to Bot → Add Bot. 2. Enable Intents & Permissions - Under Privileged Gateway Intents, toggle Message Content Intent. - Under Bot Permissions, check: - Read Messages/View Channels - Send Messages - Read Message History 3. Grab Your Token - In Bot → click Copy (or Reset Token). - Store it securely. 4. Invite Link (OAuth2 URL) - Go to OAuth2 → URL Generator. - Select scopes: bot, applications.commands. - Under Bot Permissions, select the same permissions as above. - Copy the generated URL, open it in your browser, and invite your bot. --- 3. Server Prep: Node.js & Project Setup 1. Install Node.js v20.x 2. Project Folder 3. Initialize & Dependencies --- 4. Bot Code & Configuration 1. Environment Variables - Create .env: - Populate: 2. Bot Script - Create index.js: - Implement: - Import dotenv, discord.js, axios. - Set up client with MessageContent intent. - On messageCreate: 1. Ignore bots or non‐mentions. 2. (Optional) Filter by channel ID. 3. Extract and validate the user’s question. 4. Send “typing…” every 5 s; after 20 s send a status update if still processing. 5. POST to your n8n webhook with question, channelId, userId, userName. 6. Parse various response shapes to find answer. 7. If answer.length ≤ 2000, message.reply(answer). 8. Else, split into 1900‑char chunks at sentence/paragraph breaks and send sequentially. 9. On errors, clear intervals, log details, and reply with an error message. 3. Login --- 5. Deployment: Keep It Alive with PM2 1. Install PM2 2. Start & Monitor 3. Auto‐Start on Boot --- 6. Test & Troubleshoot 1. Functional Test - In your Discord server: - Expect a reply from your n8n workflow. 2. Common Pitfalls - No reply → check pm2 logs discord-bot. - Intent Errors → verify Message Content Intent in Portal. - Webhook failures → ensure workflow is active and URL is correct. - Formatting issues → confirm your Function node returns json.answer. 3. Inspect Raw Data - Search your logs for Complete response from n8n: to debug payload shapes. --- `
Download the workflow JSON file after purchase.
Open n8n → click the menu → Import from File.
Select the downloaded JSON and import.
Set up credentials for each node that requires them.
Click Execute Workflow to test, then activate.
Setup guide included
Purchase to unlock the full step-by-step guide
No reviews yet
Be the first to buy and share your experience.
Leave a review
Sign in to share your experience with this workflow.
Create a free account to purchase workflows.
Need help setting this up?
Book a 3-hour live setup session with an Agility consultant.