Discord channel adapter for bub.
- Channel implementation:
DiscordChannel(name = "discord") - Inbound message adaptation from Discord to Bub
ChannelMessage - Outbound sending to Discord channels with:
- automatic chunking at Discord's 2000-character limit
- reply-to-latest-message behavior per session
uv pip install "git+https://github.com/bubbuild/bub-contrib.git#subdirectory=packages/bub-discord"You can also install it with Bub:
bub install bub-discord@mainDiscordChannel reads settings from environment variables with the BUB_DISCORD_ prefix.
BUB_DISCORD_TOKEN(required): Discord bot tokenBUB_DISCORD_ALLOW_USERS(optional): Comma-separated allowlist of sender identifiers- Supports user ID, username, and global name
BUB_DISCORD_ALLOW_CHANNELS(optional): Comma-separated allowlist of channel IDsBUB_DISCORD_COMMAND_PREFIX(optional, default:!)BUB_DISCORD_PROXY(optional): HTTP proxy URL for Discord API
- Session ID format:
discord:<channel_id> - Inbound messages:
- ignores bot messages
- ignores empty text messages
- applies allowlist filters when configured
- Message activation (
is_active = true) when any of these is true:- message is in DM
- message mentions the bot
- content contains
bub - content starts with
<prefix>bub - message replies to a previous bot message
- Command detection:
- if content starts with
<prefix>bub, that prefix is removed first - if remaining content starts with
,, message kind becomescommand
- if content starts with
Inbound non-command messages are encoded as JSON string content, including fields like:
messagemessage_idtypeusernamefull_namesender_iddatechannel_idguild_idreply_to_message(when present)
- Uses
session_idto resolve destination channel. - Splits long messages into multiple Discord posts.
- Replies to the latest inbound message in the same session when possible.