Discord adapter for chat-py
Project description
chat-adapter-discord
Discord adapter for chat-py. Python port of upstream packages/adapter-discord.
Targets Discord's HTTP Interactions path (signed webhooks) with REST fall-outs for post / edit / delete / reactions / typing.
Install
uv add chat-py chat-py-adapter-discord chat-py-adapter-state-memory
Auth / config
| Config field | Env var | Notes |
|---|---|---|
botToken |
DISCORD_BOT_TOKEN |
Required. Bot token from the Discord developer portal. |
publicKey |
DISCORD_PUBLIC_KEY |
Required for signature verification. |
applicationId |
DISCORD_APPLICATION_ID |
Required for slash-command + interaction routing. |
mentionRoleIds |
— | Optional; role IDs that should be treated as mentions. |
Minimal example
from chat import Chat
from chat_adapter_discord import create_discord_adapter
from chat_adapter_state_memory import create_memory_state
bot = Chat(
user_name="mybot",
adapters={"discord": create_discord_adapter()}, # reads DISCORD_* env vars
state=create_memory_state(),
)
@bot.on_slash_command("hello")
async def hello(thread, command):
await thread.post(f"Hello {command.user_name}!")
Mount bot.handle_webhook("discord", body, headers) under /api/webhooks/discord. Incoming PING interactions are acknowledged automatically; MessageComponent and ApplicationCommand interactions dispatch into the chat handler chain.
Thread ID
Discord thread IDs: discord:{channelId}:{threadId or messageId}. is_dm(thread_id) short-circuits DM detection.
Features
- Ed25519 signature verification (
verify_discord_signature) via PyNaCl - REST post / edit / delete / reactions / typing (
httpxasync client) - Button / link / select-menu card translation (
card_to_discord_payload) - Fallback text rendering (
card_to_fallback_text) for components that exceed Discord's limits - Slash command context (
DiscordSlashCommandContext,parse_slash_command) including deferred-response tracking
Parity notes
- Button style constants match upstream (
BUTTON_STYLE_PRIMARY= 1, etc.). DISCORD_MAX_CONTENT_LENGTHmirrors upstream's 2000-char limit.- Markdown ↔ mdast conversion matches
DiscordFormatConverter.
Test
uv run pytest packages/chat-adapter-discord
# Live
DISCORD_TOKEN=... uv run pytest packages/chat-integration-tests -k discord
Upstream
https://github.com/vercel/chat/tree/main/packages/adapter-discord
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file chat_py_adapter_discord-0.1.0-py3-none-any.whl.
File metadata
- Download URL: chat_py_adapter_discord-0.1.0-py3-none-any.whl
- Upload date:
- Size: 21.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.20 {"installer":{"name":"uv","version":"0.9.20","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb83b7b9feb37482d3fcab7fc2a697cd85be9287f3d54e02934382ee45af7d0a
|
|
| MD5 |
cecb203dbd5f777a5da343df3440b38e
|
|
| BLAKE2b-256 |
dfbf69e6cd1782b94ce1283c1d26a9b6377e39540f04c99a7bb90d537b597eca
|