Create a Discord application and bot, connect it to Agent Barn, restrict it to approved servers and channels, and verify that the Agent responds only to permitted operators.
An Agent Barn Discord Agent uses a bot account that you create in the Discord Developer Portal. Its runtime connects to Discord through the Gateway, and authenticates HTTP requests with the bot token.
Overview
When you finish this guide, you will have:
- A Discord application with a bot user
- The required Gateway Intents enabled
- A least-privilege installation link
- The bot installed in an approved Discord server
- Server, channel, user, role, and mention restrictions
- A running Agent verified through positive and negative access tests
| Runtime | Discord support | Server channels | Direct messages |
|---|---|---|---|
| Hermes | Supported | Supported | Disabled |
| OpenClaw | Supported | Supported | Disabled |
Discord direct messages remain disabled for Agent Barn Agents. Configure a controlled server channel for interaction.
Use a separate Discord application and bot token for every production Agent. Agent Barn prevents two active Discord Agents from using the same bot token.
Connection model
The integration follows this path.
- Discord server
- Discord Gateway and HTTP API
- Hermes or OpenClaw runtime
- Agent Barn
The runtime opens an outbound WebSocket connection to the Discord Gateway. No public webhook, callback, or Discord Interactions Endpoint URL is required for this setup.
Discord documents the Gateway as its real-time connection for receiving events from servers. The bot token authenticates both the Gateway connection and most bot HTTP API requests. See Discord’s Gateway documentation and OAuth2 and permissions guide.
Before you begin
Make sure you have:
- Access to the Agent Barn organization where the Agent will be created
- Permission to create an Agent
- Permission to manage the Agent lifecycle
- Permission to update Agent configuration
- Permission to manage Agent secrets, if you will later rotate the token
- A Discord account that can create applications
- Manage Server permission in the Discord server where the bot will be installed
- An available Hermes or OpenClaw runtime
- Model credentials, or an organization model configuration
- A test channel where the bot can safely be verified
You do not need to expose Agent Barn or its runtime through a public Discord endpoint.
Create a Discord application
The Discord Developer Portal holds three pages you will use.
- General Information Application name and the public Application ID
- Bot Bot identity, the bot token, and Privileged Gateway Intents
- Installation Install context, OAuth2 scopes, and bot permissions
This is a description of the portal navigation, not a screenshot.
Create the application
Open the Discord Developer Portal.
- Select New Application.
- Enter a recognizable name.
- Accept Discord’s developer terms when prompted.
- Select Create.
- On General Information, copy the Application ID.
Application name: Agent Barn Support
Application ID: 123456789012345678The Application ID is a public identifier, not a secret. Agent Barn uses it only to generate an installation link. Agent Barn does not create the Discord application for you.
Do not copy the Public Key or Client Secret into Agent Barn. They are not required for this integration.
New Discord applications normally include a bot user automatically. Open Bot in the portal sidebar to configure it. Discord’s current creation flow is documented in Building your first Discord bot.
Configure the bot identity
On the Bot page:
- Set the bot’s username.
- Add an icon if desired.
- Decide whether other Discord administrators should be able to install it.
- Find the Token section.
- Select Reset Token to generate the initial bot token.
- Copy the token immediately.
Discord does not display the token again after you leave the page unless you reset it. Store it temporarily in a password manager.
REDACTED_DISCORD_BOT_TOKENThe token is not the Application ID, Public Key, or Client Secret. Anyone with the token can authenticate as the bot, so Discord requires bot tokens to be treated like passwords and kept out of version control.
You now have an Application ID and a freshly generated bot token.
Enable Gateway Intents
On the application’s Bot page, scroll to Privileged Gateway Intents and enable the intents this Agent needs.
| Intent | When required | Purpose |
|---|---|---|
| Message Content Intent | Always | Allows the runtime to receive the text and related content of Discord messages |
| Server Members Intent | When using allowed role IDs | Allows the runtime to evaluate server membership and role-based access |
Without Message Content Intent, Discord may deliver message events with content-related fields removed.
For unverified applications, privileged intents can be enabled in the portal. Applications operating at Discord’s verification scale may also need Discord approval for those intents.
Configure installation
Configure the installation context
Open Installation in the Discord Developer Portal. For an Agent Barn bot:
- Enable Guild Install.
- Select Discord Provided Link if you want the portal to manage the default link.
- Include the
botscope. - Include the
applications.commandsscope. - Select only the bot permissions required for conversation.
Discord calls servers “guilds” in its API and developer settings.
OAuth2 scopes
botapplications.commands
Bot permissions
- Add Reactions
- View Channels
- Send Messages
- Send Messages in Threads
- Embed Links
- Attach Files
- Read Message History
- Use External Emojis
The recommended Agent Barn installation link uses:
https://discord.com/oauth2/authorize?client_id=APPLICATION_ID&scope=bot%20applications.commands&permissions=274878286912Replace APPLICATION_ID with the value from General Information. Agent Barn generates this link automatically when you enter the Application ID in the hiring flow.
Discord permissions remain subject to server and channel overrides. A channel can deny the bot access even if the permission was accepted during installation. See Discord’s permissions reference.
Install the bot
Open the generated installation link.
- Select Add to server.
- Choose the intended Discord server.
- Review the requested permissions.
- Select Authorize.
- Complete any verification prompt.
- Confirm that the bot appears in the server member list.
The person completing this flow must have permission to manage the selected server. Server-installed apps must be authorized by a member with Discord’s MANAGE_GUILD permission.
After installation, review the bot’s permissions in every intended channel. It must be able to:
- View the channel.
- Read message history.
- Send messages.
- Send messages in threads, if threads are used.
- Embed links or attach files, if the Agent will produce those response types.
The bot appears in the server member list with the least-privilege permission set.
Copy Discord IDs
Agent Barn access policies use Discord’s numeric identifiers rather than names.
Application ID
Developer Portal → General Information
Generates the bot installation link. Public, not a secret.
Server ID
Right-click the server icon → Copy Server ID
Allowed server IDs. Discord’s API calls this a guild ID.
Channel ID
Right-click the channel → Copy Channel ID
Allowed channel IDs, and the optional alert destination.
User or role ID
Right-click the user, or a role in server settings → Copy User ID or Copy Role ID
Allowed user IDs and allowed role IDs.
Enable Developer Mode
In the Discord desktop application:
- Open User Settings.
- Select Advanced.
- Enable Developer Mode.
Discord documents the desktop and mobile process in Where can I find my User, Server, or Channel ID?
Example identifiers:
Application ID: 123456789012345678
Server ID: 234567890123456789
Channel ID: 345678901234567890
User ID: 456789012345678901
Role ID: 567890123456789012Discord IDs are long numeric strings. Keep them as strings when using the Agent Barn API.
Do not use server names, channel names such as #support, Discord usernames, display names, or role names. Names can change, may not uniquely identify the intended resource, and are not accepted in an Agent Barn allowlist.
Connect Agent Barn
In Agent Barn:
- Open the intended organization.
- Select Hire Agent.
- Choose the Agent template.
- Select Hermes or OpenClaw.
- Select Discord as the platform.
- Continue to Connect your Discord bot.
| Agent Barn field | Value |
|---|---|
| Bot token | Secret copied from the Developer Portal |
| Application ID | Public application identifier |
| Allowed server IDs | Comma-separated Discord server IDs |
| Allowed channel IDs | Comma-separated Discord channel IDs |
| Allow all users | Whether every user inside the approved boundaries may interact |
| Allowed operator IDs | Discord user IDs used when all-user access is disabled |
| Allowed role IDs | Discord role IDs used when all-user access is disabled |
| Alert destination channel ID | Optional channel for scheduled or proactive delivery |
The Application ID is optional. It is used to generate the installation link, and is not saved as a bot credential.
The bot token is required. Agent Barn encrypts it before storage, and never returns it through Agent read responses.
Agent Barn also hashes the token to enforce uniqueness. Attempting to reuse the token of another active Discord Agent returns a conflict.
Finish the remaining Agent details and create the Agent. A new Discord Agent is created in the Stopped state.
A malformed or revoked token may not be detected until the runtime attempts to connect during startup.
Configure access
Discord access is evaluated through several independent boundaries. A message must pass every configured boundary.
- Bot is installed in the server A Discord administrator authorized the application
- Server policy permits the server Open, or the server ID is on the allowlist
- Channel policy permits the channel The channel ID is allowed, and Discord permits the bot to see it
- User or role policy permits the sender All users are allowed, or the sender matches a user or role ID
- Mention requirement permits the message The message explicitly addresses the Agent while gating is enabled
Server access
| Policy | Behavior | Recommended use |
|---|---|---|
| Allowlist | The Agent operates only in configured servers | Recommended for production |
| Open | The Agent may operate in any server containing the bot | Controlled development, or intentionally distributed bots |
For Allowlist, enter one or more server IDs:
234567890123456789, 678901234567890123An empty allowlist does not provide production access. Add the intended server before starting the Agent.
Open access does not install the bot in other servers. A Discord administrator must still authorize the bot for every server.
Channel access
Enter the channels where the Agent may operate:
345678901234567890, 789012345678901234Channel restrictions continue to apply when the server policy is Open.
Leaving Allowed channel IDs empty removes this additional Agent Barn channel restriction, allowing the runtime to operate in channels it can see within the permitted server boundary. For production, explicitly list the intended channels.
Discord’s own channel permissions apply first. An Agent Barn allowlist cannot grant access that Discord denies.
Operator access
By default, Allow all users means any person inside the approved server and channel boundaries may interact with the Agent.
For restricted access:
- Disable Allow all users.
- Enter at least one allowed user ID or allowed role ID.
- Enable Server Members Intent if role IDs are used.
Allowed user IDs:
456789012345678901
Allowed role IDs:
567890123456789012, 890123456789012345Agent Barn rejects a restricted user policy with no allowed user or role IDs.
Role access
When access is restricted, a person is allowed if:
- Their Discord user ID is listed; or
- They hold at least one listed Discord role.
Role permissions do not need to grant control over the Agent. The role ID is used only as an interaction boundary, and role names cannot replace the numeric role ID.
Mention requirement
Keep Require an explicit mention in server channels enabled.
@Agent Barn Support summarize the unresolved questionsWith mention gating enabled, ordinary channel conversation should not activate the Agent. A direct reply to one of the Agent’s messages may still be treated as addressed to that Agent.
Disabling mention gating allows ordinary messages in approved channels to reach the Agent. Use this only when the channel is dedicated to a single Agent, and the broader behavior is intentional.
Alert destination
Alert destination channel ID is optional. For Hermes, it acts as the home destination for scheduled and proactive messages. OpenClaw can use it as the target for heartbeat delivery.
Choose a channel that:
- Is in an approved server.
- Is included in the allowed channel IDs.
- Is visible to the bot.
- Allows the bot to send messages.
Recommended production configuration
Server access: Allowlist
Allowed server IDs: One or more approved server IDs
Allowed channel IDs: Explicitly configured
Allow all users: Disabled
Allowed user or role IDs: Explicitly configured
Require explicit mention: Enabled
Alert destination: Optional approved channel
Direct messages: DisabledStart the Agent
After the hiring flow completes:
- Open the new Agent.
- Review its Discord channel configuration.
- Confirm that the bot is already installed in the approved server.
- Select Start.
- Wait for the status to move through initialization.
- Confirm that it reaches Running.
During startup, Agent Barn builds the runtime configuration and supplies the encrypted bot token to the selected runtime.
If the bot token is invalid, Gateway Intents are missing, or the runtime cannot connect to Discord, the Agent may remain unhealthy or enter Error.
When changing Discord configuration later:
| Agent state | Action | Result |
|---|---|---|
| Running | Apply & Restart | Stops the Agent, saves the configuration, and starts it with regenerated runtime settings |
| Stopped or Error | Apply | Saves the configuration without starting the Agent |
The Agent reports Running, and its runtime holds an open Gateway connection.
Verify the integration
Test every boundary that matters to your deployment.
| Test | Action | Expected result |
|---|---|---|
| Allowed server and channel | Mention the Agent in an allowed channel | Agent responds |
| No mention | Send an ordinary message in the allowed channel | Agent does not respond |
| Disallowed channel | Mention the Agent in an unlisted channel | Agent does not respond |
| Disallowed server | Mention the Agent in another server | Agent does not respond |
| Allowed user | An explicitly allowed user mentions the Agent | Agent responds |
| Allowed role | A user with an allowed role mentions the Agent | Agent responds |
| Disallowed user | A user with no allowed ID or role mentions it | Agent does not respond |
| Direct message | Send the bot a direct message | Agent does not respond |
Example positive test:
@Agent Barn Support reply with "Discord connection verified"Then confirm in Agent Barn:
- The Agent remains Running.
- The inbound message appears in the Agent’s activity.
- The resolved channel and sender are correct.
- The response appears in Discord.
- The runtime logs contain no Gateway or permission error.
A Discord message appearing in Agent Barn proves that Discord delivery is working. If the message arrives but the Agent produces no useful response, investigate the model, Agent instructions, or runtime separately.
Manage the bot token
Do not:
- Commit it to the
agent-barnrepository. - Put it in an environment example with real values.
- Include it in screenshots.
- Send it through Discord.
- Store it in issue trackers.
- Reuse it across Agents.
- Place it in a URL.
- Print it in logs.
Rotate a token
To rotate a compromised or lost token:
- Open the application in the Discord Developer Portal.
- Select Bot.
- Select Reset Token.
- Complete Discord’s authorization prompt.
- Copy the new token.
- Open the Agent in Agent Barn.
- Open Keys & integrations.
- Replace the Discord bot token.
- Select Apply & Restart if the Agent is running.
- Verify the integration again.
Resetting the token invalidates the old credential. The Agent cannot reconnect until Agent Barn contains the replacement.
Updating a Discord token requires Agent secret-management permission.
Deleting a Discord Agent releases its token hash, but a deleted bot token should still be reset or retired if the Discord application is no longer used.
API reference
Discord Agents can also be created and configured through the Agent Barn API.
| Operation | Endpoint |
|---|---|
| Create Agent | POST /api/v1/organizations/{organization_id}/agents |
| Read Agent | GET /api/v1/organizations/{organization_id}/agents/{agent_id} |
| Update Discord configuration | PATCH /api/v1/organizations/{organization_id}/agents/{agent_id} |
| Start Agent | POST /api/v1/organizations/{organization_id}/agents/{agent_id}/start |
| Stop Agent | POST /api/v1/organizations/{organization_id}/agents/{agent_id}/stop |
| Read health | GET /api/v1/organizations/{organization_id}/agents/{agent_id}/healthz |
| Read logs | GET /api/v1/organizations/{organization_id}/agents/{agent_id}/logs |
Create a Discord Agent
POST /api/v1/organizations/{organization_id}/agents{
"name": "Discord Support Agent",
"platform": "discord",
"agent_type": "hermes",
"template_key": "REPLACE_WITH_TEMPLATE_KEY",
"model": "REPLACE_WITH_MODEL",
"discord_bot_token": "REDACTED",
"discord_group_policy": "allowlist",
"discord_guild_ids": [
"234567890123456789"
],
"discord_allowed_channel_ids": [
"345678901234567890"
],
"discord_allow_all_users": false,
"discord_allowed_user_ids": [
"456789012345678901"
],
"discord_allowed_role_ids": [
"567890123456789012"
],
"discord_home_channel_id": "345678901234567890",
"discord_require_mention": true,
"skill_ids": []
}The Discord Application ID is not part of the Agent configuration API. It is used by the web interface only to generate an OAuth2 installation link.
The create endpoint returns the new Agent in the Stopped state.
Start the Agent
POST /api/v1/organizations/{organization_id}/agents/{agent_id}/startNo request body is required.
Update routing
Stop the Agent first when calling the API directly, or use the web interface’s Apply & Restart workflow.
PATCH /api/v1/organizations/{organization_id}/agents/{agent_id}{
"discord_group_policy": "allowlist",
"discord_guild_ids": [
"234567890123456789"
],
"discord_allowed_channel_ids": [
"345678901234567890",
"789012345678901234"
],
"discord_allow_all_users": false,
"discord_allowed_user_ids": [],
"discord_allowed_role_ids": [
"567890123456789012"
],
"discord_home_channel_id": "345678901234567890",
"discord_require_mention": true
}Rotate the token
{
"discord_bot_token": "REDACTED"
}| Field | Purpose |
|---|---|
discord_bot_token | Secret issued from the application’s Bot page |
discord_group_policy | open or allowlist |
discord_guild_ids | Allowed Discord server IDs |
discord_allowed_channel_ids | Allowed channel IDs |
discord_allow_all_users | Allows every user inside the server and channel boundaries |
discord_allowed_user_ids | Explicitly allowed user IDs |
discord_allowed_role_ids | Roles whose members may interact |
discord_home_channel_id | Optional proactive or heartbeat destination |
discord_require_mention | Requires the bot to be explicitly addressed in server channels |
If discord_allow_all_users is false, provide at least one user ID or role ID.
Troubleshooting
The Agent enters Error or never becomes healthy
Usually a token or intent problem
Check:
- The bot token has not been reset.
- Message Content Intent is enabled.
- Server Members Intent is enabled when roles are used.
- The bot is installed in the intended server.
- The runtime can reach
discord.com. - The selected runtime supports Discord.
- No other process is using the same bot token.
- Runtime and Agent logs contain no Gateway close code.
A missing privileged intent may cause Discord to close the Gateway connection with code 4014.
The Agent is running but does not receive messages
A boundary or intent is filtering it
Confirm that:
- The message was sent in an allowed server.
- The channel ID is included in the allowlist.
- The bot can view the channel.
- The message explicitly mentions the bot.
- Message Content Intent is enabled.
- Discord’s channel permission overrides do not deny access.
- The sender passes the user or role boundary.
The Agent receives a message but cannot answer
Missing send permissions, or a model failure
Check that the bot has:
- View Channel.
- Send Messages.
- Read Message History.
- Send Messages in Threads, when applicable.
- Embed Links, if responses contain links or rich content.
- Attach Files, if responses include files.
Also review model credentials and runtime logs. Inbound delivery can succeed while response generation fails.
A user is unexpectedly blocked
Evaluate the boundaries in order
- Is the server allowed?
- Is the channel allowed?
- Is Allow all users enabled?
- If not, is the user’s numeric ID listed?
- Does the user currently hold an allowed role?
- Is Server Members Intent enabled?
- Did the message mention the bot?
Usernames and display names do not satisfy an ID allowlist.
Role-based access does not work
Membership information is required
- Enable Server Members Intent.
- Copy the role’s numeric ID rather than its name.
- Confirm that the user currently holds the role.
- Confirm that at least one role or user is configured when all-user access is disabled.
- Apply the settings and restart the Agent.
- Retest with a new message.
The bot does not need permission to manage the role. It only needs to observe the sender’s membership information.
The bot works in one channel but not another
Channel overrides or a missing ID
Discord channel overrides may deny access. Compare the bot’s effective permissions in both channels and verify:
- View Channel
- Send Messages
- Read Message History
- Send Messages in Threads
Also confirm that the second channel’s numeric ID is in Agent Barn.
The bot does not respond inside a thread
Thread permissions are separate
- Confirm that the bot can view the parent channel.
- Grant Send Messages in Threads.
- Check the configured channel restrictions.
- Mention the bot explicitly inside the thread.
- Review logs for missing-access or permission errors.
The Agent responds to ordinary conversation
Mention gating is disabled
Check Require an explicit mention in server channels. If it is disabled:
- Open the Agent’s Discord channel settings.
- Enable the mention requirement.
- Select Apply & Restart.
- Verify with an unmentioned message.
A direct reply to an Agent message can still be treated as addressed to that Agent.
The installation link does not list the server
Server management authority is required
The current Discord user must have permission to manage that server. Also verify:
- Guild installation is enabled.
- The Application ID is correct.
- The application permits the current user to install it.
- The bot has not reached an application-specific installation restriction.
Discord says the installation link is invalid
The link must carry the Application ID
Confirm that the link uses the Application ID, not the bot token:
https://discord.com/oauth2/authorize?client_id=APPLICATION_ID&scope=bot%20applications.commands&permissions=274878286912Never place the bot token in the installation URL.
Agent Barn reports that the bot token is already in use
Tokens cannot be shared between Agents
Every active Discord Agent must use a unique bot token.
Create another Discord application and bot for the new Agent. Do not stop one Agent merely to alternate a single token between runtimes.
A new token does not work
The runtime needs the replacement
After resetting the token in Discord:
- Replace it under Keys & integrations.
- Apply and restart the Agent.
- Wait for the new runtime configuration.
- Review health and logs.
- Verify that the bot is still installed in the server.
Resetting a token does not remove the bot from the server, but it immediately invalidates the old runtime credential.
Scheduled or proactive messages are not delivered
No usable alert destination
- Configure Alert destination channel ID.
- Put the destination inside an allowed server and channel.
- Confirm that the bot can send messages there.
- Restart the Agent after changing the destination.
- For Hermes, confirm that scheduled delivery is configured.
- For OpenClaw, confirm that heartbeat delivery is enabled.
Direct messages do not work
Expected: Discord DMs are disabled
This is expected. Discord direct messages are disabled for Agent Barn Agents.
Use an approved private server channel and restrict it with:
- Discord channel permissions.
- Agent Barn’s server allowlist.
- Agent Barn’s channel allowlist.
- Allowed user or role IDs.
- Explicit mention gating.
Next steps
After verifying Discord:
- Review the Agent’s health and logs
- Test a denied user, and a channel outside the allowlist
- Restrict the bot’s channel permissions and Agent configuration
- Document ownership of the Discord application and the token-rotation procedure
- Compare platform compatibility before deploying the Agent to another communication platform