How to connect a Discord agent
This guide connects a Discord bot to your Agent: someone messages the bot, the bot answers with your agent’s reply, and the conversation is remembered across messages.
Discord works differently from webhook channels like Telegram. Instead of Discord posting to a public URL, Publicus dials out to Discord and holds a persistent bot connection through its gateway service. You don’t need a public inbound URL, but the gateway service must be running.
Prerequisites
Section titled “Prerequisites”- A Discord server you manage (to add the bot and chat with it).
- An LLM provider key for the Agent (for example an OpenAI key).
- The Publicus gateway service running. It maintains bot connections; in a standard deployment it runs alongside the queue workers.
1. Create the Discord application
Section titled “1. Create the Discord application”- In the Discord Developer Portal, create an application, or open yours.
- Under Bot, press Reset Token and copy the token.
That is all you do in the developer portal. Publicus turns on the bot’s Message Content Intent for you in the next step.
2. Add the bot and set it up
Section titled “2. Add the bot and set it up”Go to Chat apps, choose New bot and then Discord bot, and save the form it opens, with Channel already set to Discord.


Then press Check the bot on its page. This is the bot’s setup:
-
Paste the bot token and press Save. Publicus checks the token with Discord, keeps it in your workspace’s secrets, and switches the bot on. It also turns on the bot’s Message Content Intent. Without it, the bot receives messages with no text.


-
Press Invite the bot to a server and pick your server. The invite asks for what an agent’s answer needs: seeing the channel and its history, posting, threads, files and reactions.
-
Under Where it listens, pick the channels the bot should listen in, then press Save where it listens. A message in any other channel, or a direct message, is ignored, and a message in a thread counts as its channel. You can also keep the bot to your own server: anyone with a public bot’s invite link can add it to theirs. Leave both empty to listen everywhere the bot is.


The setup asks Discord again every few seconds until the bot is ready, so a bot you invite in another tab shows up by itself. Each check that still fails says what to do.
The Chat app section of the bot sets what it does around each answer: reply in the chat, show typing, answer in a thread under the message, and record a thumbs up or down as feedback are on by default. Showing the agent’s progress and approving steps in the chat are off until you turn them on.
When the agent asks a question, the bot posts it under the answer. A question with a few short answers gets a button for each. One that needs a form gets Fill in the form, which sends whoever presses it a link to the form that only they see, for an hour. Who answers forms, in the same Chat app section, changes that: Anyone in the chat puts the link in the question for everyone there, and Workspace members lets only members of your workspace answer. A member whose Discord account is linked in Publicus answers without signing in. Replying in the chat answers the question too.


3. Build the flow
Section titled “3. Build the flow”The quickest route is the Discord support agent template, or Connect a channel on an agent’s card under Agents, which binds the agent to this bot. To build the flow yourself:
-
Add a Gateway trigger node (under Triggers — start the flow). Pick the bot from step 2 in its settings, connect its trigger handle to Start, then click the node’s badge on the canvas and switch Active on. This routes the bot’s incoming messages into this flow.
-
The incoming message is available on
$start:Field Expression message text {{ $start->text }}conversation id {{ $start->externalConversationId }}sender id {{ $start->externalUserId }}conversation key {{ $start->conversationKey }}Only messages people write start the flow. Discord’s own notices, such as a member joining, a pin or a boost, are ignored.


-
Wire
Start → Agent. On the Agent, setpromptto{{ $start->text }}and pick your LLM secret incredential. -
Connect a Chat Thread node to the Agent’s Memory handle, with
channel=discord,conversationId={{ $start->conversationKey }}, anduserId={{ $start->externalUserId }}. This gives the agent memory per Discord conversation.
You don’t need a node for the reply. The bot posts the agent’s answer in the conversation the message came from: in a server channel, in a thread under the message, and in a direct message, in the chat itself. An Agent node can change any of the bot’s chat options for itself in its own Chat app section.


Voice messages. A voice note arrives with empty text. For the agent to hear it, do one of these (the template does the first):
- Set the Agent’s
attachmentsto{!! json_encode($start->attachments) !!}. - Tick Discord under Type voice notes into the message from on the AI models page’s Voice messages tab. Each note is then transcribed when it arrives and becomes
$start->textfor every flow.
With both, the agent reads the transcript made on arrival, and the note is paid for once. The bot’s Chat app section says which applies. Adding a Transcribe Audio node in front of the agent is not needed.
Verify it works
Section titled “Verify it works”-
The bot: on the bot’s page, Check the bot asks Discord whether the token works, whether the Message Content Intent is on, which servers the bot is in and whether it sees the channels it listens in. Each failing check says what to fix and where. The page’s heading says whether the bot works: Working once the gateway holds its connection open and messages arrive.


-
Delivery: a message to the bot adds a row to its Received frames tab, under Chat apps.


-
Run: the message creates a completed run under Runs.
-
Reply: the bot answers, in a thread under your message when you wrote in a server channel.
-
Memory: under Conversations, a thread exists for the conversation (keyed by the channel, server conversation, and user). Send a follow-up that refers to an earlier message and confirm the agent remembers.
To try the flow before going live, start a run by hand with start data shaped like the message above. A field your start data leaves out makes an expression that reads it fail on the first attempt, naming the expression. Give such a field a default, as in {{ $start->text ?? '' }}.
Troubleshooting
Section titled “Troubleshooting”-
Nothing arrives: no run, and no row in the Received frames tab. Press Check the bot on the bot’s page first. Otherwise check, in this order, that the gateway service is running and the bot token is correct; that the Message Content Intent is on (Discord refuses a bot connection that asks for message text without it); that the bot is a member of the server (step 2); and that the channel is among those it listens in. After fixing the token or the intent yourself, save the bot: a save reconnects it.


-
The agent answers a voice note as if nothing was said: it got an empty message. See Voice messages in step 3.
-
The answer comes from a webhook, not from the bot: the flow still has a Channel / Discord send node after the agent. Delete it, and the bot answers itself.
-
The run fails: open the run under Runs for the error, commonly an empty secret or a memory node missing its
channel/conversationId.


Related
Section titled “Related”- Connect an agent to a chat channel — the channel overview.
- Connect a Slack agent — the other Socket Mode channel.
- Connect a Telegram agent — the webhook-based equivalent.
- Chat apps · Channel / Discord · Secrets · Chat Threads.