Back to Lobehub

Connect LobeHub to Discord

docs/usage/channels/discord.mdx

2.1.567.7 KB
Original Source

Connect LobeHub to Discord

By connecting a Discord channel to your LobeHub agent, users can interact with the AI assistant directly through Discord server channels and direct messages.

Prerequisites

  • A LobeHub account with an active subscription
  • A Discord account with Manage Server permission on the target server

Step 1: Create a Discord Application and Bot

<Steps> ### Go to the Discord Developer Portal

Visit the Discord Developer Portal and click New Application. Give your application a name (e.g., "LobeHub Assistant") and click Create.

Create a Bot

In the left sidebar, click Bot. Customize the bot's username and avatar as needed.

Enable Privileged Gateway Intents

On the Bot settings page, scroll down to Privileged Gateway Intents and enable:

  • Message Content Intent — Required for the bot to read message content
  • Server Members Intent — Recommended for user identification
  • Presence Intent — Optional; enable if you want the bot to access user online/offline status

Click Save Changes.

Copy the Bot Token

On the Bot page, click Reset Token to generate your bot token. Copy and save it securely.

Important: Treat your bot token like a password. Never share it publicly or commit it to version control.

Copy the Application ID and Public Key

Go to General Information in the left sidebar. Copy and save:

  • Application ID
  • Public Key

You will need all three values (Bot Token, Application ID, Public Key) in the next step. </Steps>

Step 2: Configure Discord in LobeHub

<Steps> ### Open Channel Settings

In LobeHub, navigate to your agent's settings, then select the Channels tab. Click Discord from the platform list.

Fill in the Credentials

Enter the following fields:

  • Application ID — The Application ID from your Discord app's General Information page
  • Bot Token — The bot token you generated earlier
  • Public Key — The Public Key from your Discord app, used for interaction verification

Your token will be encrypted and stored securely.

Save Configuration

Click Save Configuration. Your credentials will be saved and LobeHub will start listening for Discord events. </Steps>

Step 3: Invite the Bot to Your Server

<Steps> ### Generate an Invite URL

In the Discord Developer Portal, go to OAuth2URL Generator. Select the following scopes:

  • bot
  • applications.commands

Under Bot Permissions, select:

  • View Channels
  • Read Message History
  • Send Messages
  • Create Public Threads
  • Send Messages in Threads
  • Embed Links
  • Attach Files
  • Add Reactions (optional)

Authorize the Bot

Copy the generated URL, open it in your browser, select the server you want to add the bot to, and click Authorize. </Steps>

Step 4: Test the Connection

Back in LobeHub's channel settings for Discord, click Test Connection to verify everything is configured correctly. Then send a message to your bot in Discord to confirm it responds.

Access Policies

LobeHub gates inbound traffic with three layered settings, all under Advanced Settings and all defaulting to permissive.

Allowed User IDs (global)

A global user-level gate. When populated, only the listed users can interact with the bot — DM, group @mention, threads, all of it — regardless of DM Policy / Group Policy mode. Empty means "no user-level filter; let per-scope policies decide". Right-click a user → Copy User ID (Developer Mode must be enabled in Settings → Advanced) to grab an ID.

DMs from non-allowlisted users get a "you aren't authorized" notice. Group @mentions from non-allowlisted users get the same kind of notice posted inside the auto-created reply thread Discord makes for the @-mention — the parent channel stays quiet.

DM Policy

Controls 1:1 direct messages.

  • Open (default) — Anyone who shares a server with the bot can DM it (subject to the global allowlist when set).
  • Allowlist — DMs require the sender to be in Allowed User IDs. Differs from Open only when the list is empty: Allowlist fails closed (no DMs), Open still lets anyone DM.
  • Disabled — The bot ignores all DMs. Senders get a one-line notice pointing them at @mentioning the bot in a shared channel instead.

Discord bots can be reached by anyone in any shared server, so consider populating Allowed User IDs or switching DM Policy to Disabled if your bot is meant to be private.

Group Policy

Controls @mentions in server channels and threads.

  • Open (default) — Respond to @mentions anywhere the bot can read.
  • Allowlist — Respond only in channels listed in Allowed Channel IDs. Right-click a channel → Copy Channel ID to grab one.
  • Disabled — Ignore all server traffic; the bot only responds to DMs.

The two policies are independent. You can run a DM-only bot with groupPolicy=disabled, a channel-only bot with dmPolicy=disabled, or scope both with allowlists.

See the Channels overview for cross-platform details.

Configuration Reference

FieldRequiredDescription
Application IDYesYour Discord application's ID
Bot TokenYesAuthentication token for your Discord bot
Public KeyYesUsed to verify interaction requests from Discord
Allowed User IDsNoComma- or whitespace-separated Discord user IDs. Global gate — applies to DMs and group @mentions
DM PolicyNoopen (default), allowlist, or disabled — who is allowed to DM the bot
Group PolicyNoopen (default), allowlist, or disabled — where the bot responds to @mentions
Allowed Channel IDsNoComma- or whitespace-separated Discord channel IDs. Used when Group Policy is Allowlist

Troubleshooting

  • Bot not responding in server: Confirm the bot has been invited to the server with the correct permissions, and Message Content Intent is enabled. If Group Policy is Disabled or Allowlist, double-check the channel is in Allowed Channel IDs. If Allowed User IDs is set, the sender's user ID must be in it.
  • Bot not responding to DMs: Open Advanced Settings and confirm DM Policy is not set to Disabled. If Allowed User IDs is set, make sure the sender's Discord user ID is in it.
  • Test Connection failed: Double-check the Application ID, Bot Token, and Public Key are correct.