# Discord The `discord` extension connects a session to a bot and delivers permitted messages and reactions as session events. [`extension.gleam`](../extensions/discord/src/albedo_ext_discord/extension.gleam) declares its storage and starts its manager. The startup callback returns the service, the Python binding's routes, and the transfer adapter. See [webhooks](webhooks.md) for signed HTTP event delivery. ## Setup The [Discord service](../extensions/discord/src/albedo_ext_discord/service.gleam) creates bots with a session, name, token, and owner ID. Its routes manage bots, channel delivery, and DM access. The [terminal client](tui.md) and [web client](web.md) provide settings pages. The extension's startup starts the manager, but successful startup does not mean a bot has connected. ## Channels and delivery [`ingest.gleam`](../extensions/discord/src/albedo_ext_discord/ingest.gleam) posts messages from configured channels to the session's [inbox](inbox.md) as `event` inputs, once per message, in the transaction that advances the channel's cursor. A channel's `tool` setting steers a running turn at its next step; its `turn` setting waits for the turn to end. A mentions-only channel filters messages that do not mention the bot. The owner and allowed users can send DMs. Other DM senders create requests rather than inbox inputs. Reactions use the same delivery choices and additional filtering. Discord messages and reactions are external conversation. They are not instructions from the user or blanket approval for an action. ## Kernel binding [`discord.py`](../python/albedo_plugins/discord.py) exposes `send`, `dm`, `history`, `react`, `channels`, and `status`. Channels can be addressed by handle or name. Messages use numbers. `send` and `dm` require text or files. The binding accepts at most ten files, each at most 10 MiB, and checks that each path is a file. Host failures raise `DiscordError`. A message that needs no answer ends the turn with the core `no_reply()`; see [ending a turn without a reply](inbox.md#ending-a-turn-without-a-reply). ## Outbound routing The `discord` [outbound route](network.md) applies to REST, uploads, and the gateway websocket. The manager resolves it on every reconciliation and restarts a bot whose route changed. ## Bot process [`manager.gleam`](../extensions/discord/src/albedo_ext_discord/manager.gleam) owns bot processes and reconciles their state. [`albedo_discord.py`](../python/albedo_discord.py) implements the helper process. [`port.gleam`](../extensions/discord/src/albedo_ext_discord/port.gleam) runs one reader process per bot that owns the helper's port, its line framing, and its request IDs. It opens the helper through `open_python` in [`sdk/host_resources`](../packages/albedo_sdk/src/albedo_sdk/host_resources.gleam), with the bot's credentials added to the daemon's trusted environment and line framing, and writes and closes it through [`albedo_ports`](../packages/albedo_ports/src/albedo_ports.gleam). Ordinary requests have a 15-second timeout. Catch-up uses 60 seconds. The [startup callback](../extensions/discord/src/albedo_ext_discord/extension.gleam) creates a `manager.Manager` handle and returns the plugins that use it. The service, the kernel routes, and the transfer adapter each capture that handle, and application code reaches the manager only through it. The handle names the actor with a name made fresh at startup, so the supervisor's restart of a crashed manager answers the same handle. The name is registered, so this is an interface boundary rather than isolation: Erlang code that enumerates registered names can still find the manager. Do not do that outside test probes. Each store's startup starts its own manager. [`owner.gleam`](../extensions/discord/src/albedo_ext_discord/owner.gleam) runs the manager's supervisor in an owner process and registers the owner's stop with `store.stop_before_close`. Startup succeeds only after the manager has initialized and the store has accepted that registration. A failed startup returns only after the owner has stopped the supervisor. At store close the stop returns once the supervisor and the manager have terminated. A startup failure is distinct from a bot's connection state. ## Related pages - [All topics](README.md) - [Change guidance](contributing.md) - [Webhooks](webhooks.md) - [Inbox](inbox.md) - [Session attachment](sessions.md)