A Discord bot built with n8n and AI can respond to messages au­to­mat­i­cal­ly, process content, and handle tasks in the back­ground. Discord, n8n, and an AI model work together to analyze incoming messages and trigger suitable responses or actions. These bots are useful for automated com­mu­ni­ca­tion, mod­er­a­tion, and con­nect­ing external services to a Discord server.

n8n Hosting
Your best VPS—maximize pro­duc­tiv­i­ty with n8n au­toma­tion
  • Automate manual routines for tech teams
  • Au­toma­tion on your own server: no task limits, full cost control
  • Over 500 in­te­gra­tions and tools thanks to open source

What are the benefits of a n8n Discord bot?

A Discord bot built with n8n lets you automate many processes without tra­di­tion­al software de­vel­op­ment. Instead of coding a complete bot from scratch in Python or JavaScript, you create a visual workflow in n8n using in­di­vid­ual building blocks. This makes it es­pe­cial­ly useful if you’re just getting started with au­toma­tion.

Further ad­van­tages at a glance:

  • Changes can be im­ple­ment­ed more easily later on, because you can adjust in­di­vid­ual steps directly in the interface.
  • At the same time, you can extend your n8n Discord bot with AI features, for example for automatic replies, summaries, or mod­er­a­tion as­sis­tance.
  • n8n can also be connected to numerous other services, so your bot can not only respond to Discord messages but also process data from other tools. Possible options include links to Google Sheets, databases, CRMs or helpdesk systems. You can also integrate tools like Jira into n8n, for example to create tickets au­to­mat­i­cal­ly or post status updates in Discord.
  • Good trace­abil­i­ty: You can see exactly what happens in the workflow and when. This makes trou­bleshoot­ing and later im­prove­ments easier.
  • Stan­dard­ized recurring tasks: Teams and companies can use n8n to stan­dard­ize recurring processes.
Note

In addition to Discord, you can integrate other com­mu­ni­ca­tion platforms with n8n. With n8n and Telegram or an n8n Telegram bot, you can create similar au­toma­tions for Telegram or combine workflows across platforms.

What are the re­quire­ments for creating an n8n Discord bot?

Before you start creating a Discord bot based on n8n and AI, you should meet a few basic re­quire­ments. Proper prepa­ra­tion makes it much easier to get started and ensures that the in­di­vid­ual com­po­nents work together smoothly later on. Many of the required accounts can be set up in just a few minutes, but it’s still worth having every­thing fully ready in advance. To implement this, you’ll need:

  • A publicly ac­ces­si­ble, running n8n instance (with HTTPS)
  • A Discord account
  • A Discord server on which you have ad­min­is­tra­tive rights
  • Access to the Discord Developer Portal
  • A bot token for your Discord bot
  • A webhook and a bot connected to Discord
  • An API access to an AI service, for example OpenAI
  • Some time for the initial testing and ad­just­ments
Tip

If you haven’t installed n8n yet, you can use an n8n Docker in­stal­la­tion. This option is par­tic­u­lar­ly suitable for beginners, since it allows you to start n8n quickly and in an isolated en­vi­ron­ment. For pro­duc­tion en­vi­ron­ments or larger ap­pli­ca­tions, an n8n Ku­ber­netes in­stal­la­tion is a good al­ter­na­tive, enabling you to run workflows in a scalable and fail-safe way.

For beginners, it’s best to first create your own Discord server for testing. This lets you try out your n8n workflow at your own pace and fix errors without affecting an existing or live server.

How to create an n8n Discord bot with AI step by step

Step 1: Prepare a Discord server for testing

If you don’t have your own test server yet, create one first. Open Discord, click the plus icon in the left sidebar, and create a new server. Give it a name. This server will later be used to safely test your n8n Discord Bot.

A dedicated test server is useful because it lets you test messages, per­mis­sions, and responses in a con­trolled en­vi­ron­ment. Small mistakes can happen quickly, es­pe­cial­ly when you’re new to au­toma­tions. In a test en­vi­ron­ment, they are much easier to fix. Make sure you have ad­min­is­tra­tor rights on the server.

Step 2: Create an ap­pli­ca­tion in the Discord Developer Portal

Open the Discord Developer Portal and log in with your Discord account. Click “New Ap­pli­ca­tion” and give your ap­pli­ca­tion a name. This ap­pli­ca­tion will form the basis of your n8n Discord bot.

Then switch to the “Bot” section and create the actual Discord bot there. Discord will now generate a bot profile that can later com­mu­ni­cate with your workflow. The so-called bot token is es­pe­cial­ly important. This token works like a password for your n8n Discord Bot and will later be stored in n8n. Keep the token con­fi­den­tial. Anyone with access to it can misuse your bot or perform actions in its name.

Image: Discord Developer Portal: Create bot
In the Discord Developer Portal, you can create your bot.

Step 3: Define the necessary per­mis­sions for the bot

For your bot to work on your server, it needs the right per­mis­sions. You can define these in the Developer Portal. For a simple AI-based n8n Discord bot, the following per­mis­sions are usually enough to get started:

  • Read messages
  • Send messages
  • Read message history
  • Embed links
  • Send at­tach­ments

Depending on your use case, ad­di­tion­al per­mis­sions may be required later, for example for mod­er­a­tion, role man­age­ment, or channel in­ter­ac­tions. For beginners, however, it’s a good idea to enable only the per­mis­sions that are really needed. That keeps things clearer and more secure.

Image: Discord Developer Portal: Bot Permissions
In the “Bot Per­mis­sions” section, you can assign per­mis­sions for your bot.

Step 4: Invite the bot to the Discord server

In the next step, create an in­vi­ta­tion link for your n8n Discord bot so you can add it to your Discord server. To do this, go to the “OAuth2” section in the Discord Developer Portal and open the “OAuth2 URL Generator.”

Under Scopes, enable at least the “bot” option and, if you want to use slash commands, also “ap­pli­ca­tions.commands.” Then select the per­mis­sions your bot should have later, for example reading and sending messages. Based on this selection, Discord au­to­mat­i­cal­ly generates a URL. Open this link, choose your (test) server, and confirm the in­vi­ta­tion.

Image: Discord Developer Portal: URL Generator
Use the URL Generator to add your bot to the server.

After that, the bot will appear on your server. It’s normal that it doesn’t respond to messages yet, because you’ll set up the actual func­tion­al­i­ty and logic for your n8n Discord bot in the next step.

Step 5: Create a Discord webhook

For many workflows, a webhook is the easiest way to send messages from n8n to Discord. However, webhooks are an outbound-only channel. For in­ter­ac­tive bots that respond to user input (for example, slash commands), a webhook alone is not enough. For that, you also need in­ter­ac­tions, which are set up in Step 7.

Open the settings of the desired text channel in Discord and go to “In­te­gra­tions.” There you can create a new webhook. Assign a name, select the channel, and copy the webhook URL. You will enter this URL in n8n later. This allows n8n to au­to­mat­i­cal­ly send messages to Discord without you having to write your own bot program logic.

Image: n8n: Webhook POST
Enter the webhook URL in n8n.
Note

A webhook is a good option for your first au­toma­tions. If you later need more complex in­ter­ac­tions, such as re­spond­ing to specific Discord messages, you can also work with bot logic, slash commands, or external triggers.

Step 6: Open n8n and create a new workflow

Open your n8n instance and create a new workflow. Give it a mean­ing­ful name. Unlike simple au­toma­tions, a real n8n Discord bot is not just about sending messages. Your workflow also needs to be able to receive incoming requests from Discord and respond to them.

A typical structure consists of three parts:

  • Input (Discord → n8n)
  • Pro­cess­ing (AI)
  • Output (n8n → Discord)

Step 7: Connect Discord and n8n (in­ter­ac­tions)

Unlike webhooks, which are only used to send outgoing messages, in­ter­ac­tions allow Discord to send data into your workflow. These are struc­tured requests triggered by actions such as slash commands. Whenever a user runs such a command in Discord, Discord sends a request to a URL you define. This is the URL you provide in n8n for your n8n Discord bot.

First, create a Webhook node in your workflow. This node serves as the entry point for all requests coming from Discord. Open the Webhook node settings and select POST as the method. Then assign a path, for example, discord-interaction.

As soon as you save these settings, n8n au­to­mat­i­cal­ly generates a webhook URL. The interface shows two variants: a test URL and a pro­duc­tion URL. The test URL is only suitable for short tests in the editor. To run your n8n Discord bot later, you need the pro­duc­tion URL, because it also works when the workflow is active.

Next, store this URL in Discord. Open the Discord Developer Portal and go to the ap­pli­ca­tion you created earlier. In the “General In­for­ma­tion” section, you’ll find the “In­ter­ac­tions Endpoint URL” field. Enter the pro­duc­tion URL from n8n here and save your changes.

Signature ver­i­fi­ca­tion and ping ver­i­fi­ca­tion

For Discord to accept your In­ter­ac­tions Endpoint URL and use it per­ma­nent­ly, your endpoint must meet two key re­quire­ments:

  1. Respond to ping ver­i­fi­ca­tion: When setting things up, Discord au­to­mat­i­cal­ly sends a test request with the following content:

    {
    "type": 1
    }

Your endpoint must respond to this with an unchanged so-called pong response. This indicates that your endpoint is reachable. The following response should therefore be sent:

```
 {
   "type": 1}
 ```
  1. Perform signature ver­i­fi­ca­tion: In addition, Discord checks every incoming request using the security headers X-Signature-Ed25519 and X-Signature-Timestamp. This signature ensures that the request actually comes from Discord and has not been tampered with in transit. For pro­duc­tion ap­pli­ca­tions, this ver­i­fi­ca­tion is mandatory.
Note

Complete signature ver­i­fi­ca­tion (Ed25519) cannot be im­ple­ment­ed in n8n without ad­di­tion­al logic or external services. By default, n8n does not provide native support for verifying these sig­na­tures.

For simple tests, you can still use the endpoint. However, for stable pro­duc­tion operation, you need to place ad­di­tion­al mid­dle­ware in front that handles the signature ver­i­fi­ca­tion.

Typical workaround for pro­duc­tion setups

In practice, the following ar­chi­tec­ture is often used:

Discord -> Mid­dle­ware (signature ver­i­fi­ca­tion) -> n8n webhook

The mid­dle­ware can, for example, be im­ple­ment­ed as a small stand­alone service, such as a simple Node.js server, a server­less function (for example, using Cloud­flare Workers), or as part of an existing backend service. The specific tech­nol­o­gy is not what matters, but rather the function of this in­ter­me­di­ate layer.

This component sits logically between Discord and your n8n instance and handles several key tasks. First, it checks every incoming request using the provided signature to ensure that the data really comes from Discord and has not been tampered with. It also correctly answers the ping request sent by Discord, which is required to verify the endpoint.

Only after these checks have been suc­cess­ful­ly completed does the mid­dle­ware forward the request to the actual n8n webhook. This way, your n8n Discord bot workflow receives only validated and trust­wor­thy data and can continue pro­cess­ing as usual.

Note

Discord only accepts HTTPS URLs for the In­ter­ac­tions Endpoint. Therefore, make sure that your n8n instance is ac­ces­si­ble via HTTPS, for example through your own domain with an SSL cer­tifi­cate.

This es­tab­lish­es the con­nec­tion. Whenever a user runs a slash command, Discord au­to­mat­i­cal­ly sends the relevant data to your n8n Discord bot workflow and starts it.

Step 8: Create a slash command for the bot

So that users can trigger your n8n Discord bot directly in the chat, you need a so-called slash command. These ap­pli­ca­tion commands are created via the Discord API.

Before you create the slash command, you need two important values from the Discord Developer Portal:

  • Ap­pli­ca­tion ID: You can find this in the “General In­for­ma­tion” section of your ap­pli­ca­tion.
  • Bot token: You can find this in the “Bot” section. Treat the token as con­fi­den­tial, as it grants access to your bot.

The command itself is created via an HTTP request to the Discord API. You can execute this request either through a terminal or directly using a tool like n8n. An example using curl looks like this:

curl -X POST https://discord.com/api/v10/applications/YOUR_APPLICATION_ID/commands \
-H "Authorization: Bot YOUR_BOT_TOKEN" \
-H "Content-Type: application/json" \
-d '{
    "name": "ask",
    "description": "Ask the bot a question",
    "options": [
        {
            "name": "question",
            "description": "Your question",
            "type": 3,
            "required": true
        }
    ]
}'
bash

Replace the following:

  • YOUR_APPLICATION_ID with your actual ap­pli­ca­tion ID
  • YOUR_BOT_TOKEN with your bot token

This request creates a new slash command named /ask. In addition, it defines an input option called “question” that users can use to pass a message to the n8n Discord bot.

Once the request has been executed suc­cess­ful­ly, the new command is available. Open your Discord server and click in a text input field. Type /, and your new command should appear au­to­mat­i­cal­ly in the sug­ges­tion list.

VPS Hosting (Virtual Private Servers)
More scale, same great pricing — with the new VPS+
  • NEW: VM cloning, load balancing, block storage, and more
  • Ideal for agentic AI, LLMs, and au­toma­tion at scale
  • Free 24/7 expert support and 99.99%+ uptime
  • Unlimited traffic and no setup fees

Step 9: Process incoming data from Discord

As soon as a slash command is executed, Discord sends a struc­tured request to your webhook. To further process the included in­for­ma­tion, add a Set node after the webhook. There, extract the relevant data, es­pe­cial­ly the username and the entered message, using JSON ex­pres­sions.

Example:

{
"username": "{{$json.member.user.username}}",
"message": "{{$json.data.options[0].value}}"
}
json

This gives you the most important in­for­ma­tion in a clear, well-organized format.

Note

The exact fields can vary depending on the command type, context, and option structure, so always check the actual output of the last execution in n8n.

Image: n8n: Process data
You process the incoming data from Discord in n8n using a Set node.

Step 10: Pass the message to an AI model

In the next step, connect your workflow to an LLM. In n8n, you can either use the OpenAI node for this or directly call an API with an HTTP Request node. The current OpenAI node in n8n supports the OpenAI Responses API. For beginners, the easiest way is usually the OpenAI node.

If you are using the node for the first time, you must first add your cre­den­tials. In the node, click “Cre­den­tials” and select “Create New Cre­den­tial.” Enter your API key there and save the cre­den­tials.

Next, configure the node so that the incoming Discord message is passed to the model. Select a text or message operation and enter a prompt that defines the desired context for the AI. A simple template might be:

You are a helpful assistant in a Discord server.
Respond politely and clearly in a maximum of five sentences.
User: {{$json.username}}
Message: {{$json.message}}
txt

Make sure you don’t enter the username and message values manually. Instead, insert them as ex­pres­sions from the previous node.

Step 11: Prepare the response for Discord

The response from an AI node in n8n often consists not only of plain text, but also of struc­tur­al and metadata. To ensure that Discord later receives only the actual reply, you process the result in an ad­di­tion­al step. Add another Set node after the AI node. There, create a new field named reply. In this field, insert the response text from the AI node’s result.

A typical example looks like this:

{
"reply": "{{$json.output[0].content[0].text}}"
}
json

If your output is struc­tured dif­fer­ent­ly, you can easily check this by looking at the OpenAI node’s output after a test run. There you can see exactly where the actual response text is located.

Op­tion­al­ly, you can further format the response, for example with a prefix. This way, the raw AI reply can be turned into a slightly nicer Discord output:

{
"reply": "**AI bot:** {{$json.reply}}"
}
json

Step 12: Return the response directly to Discord

This step is important because Discord in­ter­ac­tions do not expect a generic webhook response. Your endpoint must return a valid in­ter­ac­tion response to the slash command request.

In n8n, you can handle this by making the webhook node wait until the workflow has finished and then return the result of the final step. This means the webhook node does not respond im­me­di­ate­ly, but only after the last node in the workflow has run.

Click the webhook node again at the beginning of the workflow. In the settings, look for the “Respond” section. Instead of selecting an immediate response, choose “When Last Node Finishes”.

Image: n8n: Edit webhook
Edit your webhook in n8n so that it responds when the last node is finished.
Tip

Keep Discord’s rate limits in mind. Both webhooks and API calls are limited. Discord uses dynamic rate limits for webhooks and API requests, which vary depending on the endpoint and usage. If too many requests are sent in a short time, Discord returns an error with HTTP 429. To avoid issues, replies should be throttled or delayed instead of being sent without restraint.

Below that, you’ll find the setting for the response data. Select “First Entry JSON” so that n8n returns exactly the JSON object that comes from the last node.

For Discord to accept the response, your last node must output a JSON object that looks roughly like this:

{
"type": 4,
"data": {
"content": "{{$json.reply}}"
}
}
json

In practice, this means you add another Set node after your existing reply node. In this final node, you set up the fields so that this exact structure is created. A field called type gets the value 4. Another field called data in turn contains the subfield content with your AI response.

Image: n8n: Set node with formatting
In the final node, you format the data using JSON.
Note

Discord in­ter­ac­tions have an important lim­i­ta­tion. Your endpoint must return an initial response within 3 seconds. If no valid response is sent during that time, Discord discards the request and the in­ter­ac­tion token becomes invalid. This can become an issue when using AI models, because pro­cess­ing often takes longer.

In these cases, it’s better not to send the full reply im­me­di­ate­ly, but to first return a deferred response.

To do this, use the response type type: 5 (DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE). This tells Discord that the request was received and that the actual reply will follow later. You can then send the completed response as a follow-up message. The in­ter­ac­tion token remains valid for up to 15 minutes for this purpose.

Step 13: Thor­ough­ly test the workflow

Before you use the bot per­ma­nent­ly, you should carefully test the entire process. First, activate the workflow, because pro­duc­tion webhook URLs in n8n only work when the workflow is active. n8n also clearly dis­tin­guish­es between test and pro­duc­tion URLs. The pro­duc­tion URL is the correct address for Discord. Then switch to your Discord server and enter the slash command, for example:

/ask question: What is n8n?

As soon as you send the command, Discord should forward the request to your in­ter­ac­tions endpoint. Then open the execution list in n8n. There, you can click through each step and check which data was received and how it was processed. If every­thing is working correctly, a reply will appear in Discord.

Practical use cases for n8n Discord Bots with AI

With n8n, you can build not just a simple reply bot, but automate many different Discord workflows. The following examples show three practical ideas that are also easy for beginners to follow.

Example 1: FAQ bot for community questions

An FAQ bot au­to­mat­i­cal­ly answers recurring standard questions. This is es­pe­cial­ly useful if similar questions about products, rules, opening hours, or processes keep coming up on your server. The AI can interpret an incoming question and answer it in a friendly, concise way. Op­tion­al­ly, you can also retrieve fixed, stored in­for­ma­tion from a table, a database, or an internal document. This way, users get answers faster without mod­er­a­tors having to respond to every question manually. This saves a lot of time, es­pe­cial­ly on support or community servers.

Image: n8n: Discord FAQ bot example
For an FAQ bot, you use not only AI but also a database with pre­vi­ous­ly stored questions.

Example 2: Mod­er­a­tion bot for pre-checking messages

A mod­er­a­tion bot can analyze new messages and detect prob­lem­at­ic content at an early stage. The AI can check, for example, whether a message is offensive, spam-like, or off-topic. In n8n, you can then define rules for what should happen in each case. For instance, you can send a warning to a mod­er­a­tion team or forward a message to a review channel. The bot does not replace human mod­er­a­tion, but it can help sort content more quickly. This can sig­nif­i­cant­ly reduce mod­er­a­tion effort, es­pe­cial­ly in larger com­mu­ni­ties.

Image: n8n: moderation bot example
In com­bi­na­tion with Discord, n8n can be used to build a bot that checks for spam.

Example 3: Summary bot for longer dis­cus­sions

On active Discord servers, important in­for­ma­tion can quickly get buried in long message threads. A summary bot can bundle multiple messages at regular intervals or on request and turn them into a short overview. This is useful for project servers, learning com­mu­ni­ties, and internal team channels. n8n collects the relevant messages, sends them to the AI, and posts the summary in a defined channel. This saves users from having to read every con­ver­sa­tion in full and makes key in­for­ma­tion easier to find.

Image: n8n: summary bot example
If you pe­ri­od­i­cal­ly retrieve many messages from Discord with n8n, you can use the AI to summarize them.

Reviewer

Go to Main Menu