Aleph
Interfaces

Discord

Discord Bot interface for Aleph -- bot creation, permissions, and guild configuration

The Discord interface connects Aleph to Discord using the serenity framework. It supports guild (server) channels, direct messages, file attachments, embeds, reactions, Markdown formatting, and slash commands.

Capabilities

FeatureStatus
Text messagesSupported
MarkdownSupported
File attachmentsSupported (send and receive)
ImagesSupported (send and receive)
Audio/VideoSupported (send and receive)
Message reactionsSupported
Reply threadingSupported
Message editingSupported (with channel context)
Message deletionSupported (with channel context)
Typing indicatorSupported
EmbedsSupported (outbound)
Slash commandsConfigurable
Max message length2,000 characters
Max attachment size25 MB (100 MB with Nitro)

Prerequisites

Create a Discord Application

  1. Go to the Discord Developer Portal
  2. Click New Application and give it a name (e.g., "Aleph")
  3. Navigate to the Bot section in the left sidebar
  4. Click Add Bot and confirm
  5. Under the bot's token section, click Copy to get your bot token

Configure Bot Intents

Still in the Developer Portal, under the Bot section:

  1. Scroll down to Privileged Gateway Intents
  2. Enable Message Content Intent (required to read message text)
  3. Enable Server Members Intent if you need member-related features
  4. Save changes

The Message Content Intent is a privileged intent. Without it, the bot cannot read message text in guild channels. Discord requires verification for bots in 100+ servers.

Generate an Invite URL

Navigate to OAuth2 > URL Generator:

  1. Under Scopes, select bot and applications.commands
  2. Under Bot Permissions, select:
    • Send Messages (required)
    • View Channel (required)
    • Read Message History (required)
    • Embed Links (recommended)
    • Attach Files (recommended)
    • Add Reactions (recommended)
    • Use Slash Commands (optional)
    • Manage Messages (optional, for cleanup)
  3. Copy the generated URL and open it in your browser to invite the bot to your server

Enable the Discord Feature

Build Aleph with the discord feature flag:

cargo build --release --features discord
# or for all interfaces:
cargo build --release --features all-interfaces

Configuration

Minimal Configuration

[[channels]]
id = "discord"
channel_type = "discord"
enabled = true

[channels.config]
bot_token = "MTIzNDU2Nzg5MDEyMzQ1Njc4OQ.ABcDeF.1234567890abcdefghijklmnop"

Full Configuration Reference

[[channels]]
id = "discord"
channel_type = "discord"
enabled = true

[channels.config]
# Bot token from Discord Developer Portal (required)
# Supports ${ENV_VAR} expansion
bot_token = "${DISCORD_BOT_TOKEN}"

# Application ID for slash commands registration (optional)
application_id = 123456789012345678

# Guild (server) allowlist -- empty means allow all guilds
allowed_guilds = [123456789012345678]

# Channel allowlist within guilds -- empty means allow all channels
allowed_channels = [987654321098765432]

# Allow direct messages (default: true)
dm_allowed = true

# Prefix for text commands (default: "!")
command_prefix = "!"

# Respond only when mentioned in guilds (default: true)
respond_to_mentions = true

# Register and use slash commands (default: true)
slash_commands_enabled = true

# Send typing indicator while processing (default: true)
send_typing = true

# Gateway intents configuration
[channels.config.intents]
guild_messages = true      # Receive guild messages (default: true)
direct_messages = true     # Receive DMs (default: true)
message_content = true     # Read message content (default: true, privileged)
guild_members = false      # Track guild member events (default: false, privileged)

Discord bot tokens are long Base64-encoded strings (typically 59+ characters). Aleph validates the token length at config load time.

Environment Variable Mode

export DISCORD_BOT_TOKEN="MTIzNDU2..."
export DISCORD_APPLICATION_ID="123456789012345678"  # Optional

Permission Audit

Aleph includes a built-in permission audit system that checks the bot's permissions in each guild. Permissions are categorized into three levels:

Required Permissions

These are essential for basic operation:

PermissionFlagPurpose
Send Messages0x800Send responses
View Channel0x400See channels the bot is in
Read Message History0x40000Read conversation context

These enable richer interaction:

PermissionFlagPurpose
Embed Links0x4000Rich message embeds
Attach Files0x8000Send file attachments
Add Reactions0x40React to messages

Optional Permissions

PermissionFlagPurpose
Manage Messages0x2000Delete/pin messages
Use Slash Commands0x80000000Register slash commands

The audit produces a traffic-light assessment:

  • Green (Healthy) -- All required and recommended permissions granted
  • Yellow (Degraded) -- Required permissions present, some recommended missing
  • Red (Critical) -- Missing required permissions; bot cannot function

You can check permission status via the interface.status RPC method.

Message Routing

Guild Channel Messages

In guild channels, the bot processes messages when:

  1. The message is not from a bot (prevents self-loops)
  2. The guild is in allowed_guilds (or the list is empty)
  3. The channel is in allowed_channels (or the list is empty)
  4. The bot is mentioned, or the message starts with command_prefix, or respond_to_mentions is false

When respond_to_mentions is true (default), the bot only responds to messages that @mention it or use the command prefix. This prevents the bot from responding to every message in a busy channel.

The mention text is automatically stripped from the message before routing to the agent.

Direct Messages

DMs are processed whenever dm_allowed is true. No prefix or mention is required -- all DM text is forwarded directly to the agent.

Conversation IDs

ContextConversation ID
Guild channelChannel ID (e.g., 987654321098765432)
Direct messagedm:{user_id} (e.g., dm:123456789012345678)

Session Routing

Each Discord conversation maps to a session key:

ContextSession Key
DM with useragent:main:dm:{user_id} or agent:main:discord:dm:{user_id}
Guild channelagent:main:discord:group:{channel_id}

Attachments

Receiving Attachments

Discord attachments are extracted with full metadata:

Attachment {
    id: "attachment_id",
    mime_type: "image/png",      // From content_type or default
    filename: Some("image.png"), // Original filename
    size: Some(12345),           // Size in bytes
    url: Some("https://cdn.discordapp.com/..."), // CDN URL
}

Sending Attachments

Outbound attachments are sent as Discord file attachments. Currently, in-memory byte data is supported:

let msg = OutboundMessage::text("channel_id", "Here is the file")
    .with_attachment(Attachment {
        data: Some(file_bytes),
        filename: Some("output.txt".to_string()),
        ..Default::default()
    });

Reply Threading

When the agent responds to a specific message, Discord's reply reference is used:

  • Inbound messages include reply_to if the user replied to a previous message
  • Outbound messages can set reply_to to create a reply chain

This creates the visual reply indicator in Discord's UI.

Slash Commands

When slash_commands_enabled is true and application_id is set, Aleph can register slash commands with Discord. These appear in the command picker when users type /:

  • /ask -- Send a message to Aleph
  • /status -- Check Aleph's status
  • /help -- Show available commands

Slash command registration requires the applications.commands OAuth2 scope. Global commands may take up to an hour to propagate; guild-specific commands are instant.

Error Handling

ErrorBehavior
Invalid bot tokenClient fails to build; channel enters Error state
Missing intentsBot connects but cannot read messages; check Developer Portal settings
Guild not in allowlistMessages from that guild are silently ignored
Channel not in allowlistMessages from that channel are silently ignored
Bot not mentionedMessage is skipped when respond_to_mentions is true
Rate limitingSerenity handles Discord rate limits automatically

Gateway Intents

Discord requires bots to declare which events they want to receive. Aleph's intent configuration maps directly to Discord Gateway Intents:

[channels.config.intents]
guild_messages = true      # GUILD_MESSAGES intent
direct_messages = true     # DIRECT_MESSAGES intent
message_content = true     # MESSAGE_CONTENT intent (privileged)
guild_members = false      # GUILD_MEMBERS intent (privileged)

Privileged intents (message_content and guild_members) must be enabled in the Discord Developer Portal before they can be used. If your bot is in 100+ guilds, Discord requires bot verification before granting these intents.

Troubleshooting

ProblemSolution
Bot is online but does not respondEnable Message Content Intent in the Developer Portal
Bot ignores messages in a channelCheck allowed_guilds and allowed_channels; verify the bot has View Channel permission
Bot responds to every messageSet respond_to_mentions = true or use a command_prefix
"Failed to create Discord client"Verify the bot token is valid and long enough (59+ characters)
Slash commands do not appearEnsure application_id is set and the bot was invited with applications.commands scope
Permission audit shows RedUse the audit's fix_suggestions to grant missing permissions in Server Settings
Attachments fail to sendCheck that the bot has the Attach Files permission in the target channel

On this page