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.
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.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.