Discord Interactive Components (Components v2)
Send rich, interactive messages in Discord using the message tool's components parameter. This replaces plain text with buttons, select menus, modals, and structured layouts.
When to Use Components v2
ALWAYS prefer components over plain text when:
- - You need user confirmation → buttons (Yes/No, Approve/Reject)
- You need user selection → select menus (agents, priorities, options)
- You want structured information display → text blocks + sections + separators
- You want to collect form data → modals with text inputs, selects, checkboxes
- You want visual distinction → accent-colored containers
Use plain text when:
- - Simple conversational response, no actions needed
- Quick one-liner answer
Quick Reference
The components parameter is an object with this structure:
CODEBLOCK0
Quick Start — Confirmation
CODEBLOCK1
No custom_id needed — OpenClaw generates unique IDs automatically. When the user clicks, you receive a message like INLINECODE4
Key Differences from Raw Discord API
| What you might expect | What OpenClaw actually uses |
|---|
| INLINECODE5 wrapper | INLINECODE6 config object |
| INLINECODE7 |
type: "text" in blocks |
|
type: "action_row" with nested components |
type: "actions" with
buttons or
select |
| Manual
custom_id on buttons | Auto-generated — just set
label and
style |
|
accent_color: 0x3498db |
accentColor: "#3498db" (hex string preferred) |
|
type: "string_select" |
select: { type: "string", ... } inside actions block |
Block Types Summary
| Block Type | Purpose | See |
|---|
| INLINECODE20 | Markdown text | components.md |
| INLINECODE21 |
Text + optional thumbnail/button |
components.md |
|
separator | Divider line |
components.md |
|
actions | Buttons or select menu |
components.md |
|
media-gallery | Image gallery |
components.md |
|
file | File attachment |
components.md |
Handling Interactions
When a user clicks a button or selects an option, OpenClaw delivers it as a normal inbound message:
- - Button click → INLINECODE26
- Select → INLINECODE27
No special callback handling needed — just read the incoming message text. See handling.md for patterns.
Important Rules
- - No
custom_id — OpenClaw auto-generates unique IDs for all interactive elements - No
embeds — Components v2 and embeds cannot coexist in the same message reusable: true — Set this to allow buttons/selects to be clicked multiple timesallowedUsers — Optionally restrict who can click a button (array of Discord user IDs)- Actions block — Must have EITHER
buttons OR select, never both - Max 5 buttons per actions block, max 1 select per actions block
Examples
See references/examples.md for complete scenarios:
- - Yes/No confirmation
- Agent/option selection
- Status card with actions
- Modal form collection
- Multi-step workflow
Discord 交互组件 (Components v2)
使用 message 工具的 components 参数在 Discord 中发送丰富、交互式消息。这将纯文本替换为按钮、选择菜单、模态框和结构化布局。
何时使用 Components v2
当以下情况时,始终优先使用组件而非纯文本:
- - 需要用户确认 → 按钮(是/否,批准/拒绝)
- 需要用户选择 → 选择菜单(代理、优先级、选项)
- 需要结构化信息展示 → 文本块 + 分区 + 分隔线
- 需要收集表单数据 → 带文本输入、选择、复选框的模态框
- 需要视觉区分 → 强调色容器
使用纯文本的情况:
快速参考
components 参数是一个具有以下结构的对象:
json5
{
// 顶层字段
text: 可选的顶层文本(作为第一个 TextDisplay 渲染),
reusable: true, // 保持按钮/选择菜单可多次点击(默认:单次使用)
container: {
accentColor: #3498db, // 左边框颜色(十六进制字符串或数字)
spoiler: false
},
// 内容块(按顺序在容器内渲染)
blocks: [
{ type: text, text: Markdown 文本块 },
{ type: section, text: 主要文本, accessory: { type: thumbnail, url: https://... } },
{ type: separator, spacing: small, divider: true },
{ type: actions, buttons: [{ label: 点击我, style: success }] },
{ type: actions, select: { type: string, placeholder: 选择..., options: [...] } },
{ type: media-gallery, items: [{ url: https://..., description: ... }] },
{ type: file, file: attachment://report.pdf }
],
// 可选的模态框表单(自动生成触发按钮)
modal: {
title: 表单标题,
triggerLabel: 打开表单,
fields: [{ type: text, label: 您的姓名 }]
}
}
快速入门 — 确认
json5
// message 工具调用
{
action: send,
channel: discord,
target: channel:频道ID,
components: {
text: 确认操作?,
reusable: false,
container: { accentColor: #3498db },
blocks: [
{
type: actions,
buttons: [
{ label: 是, style: success },
{ label: 否, style: secondary }
]
}
]
}
}
无需 custom_id — OpenClaw 会自动生成唯一 ID。当用户点击时,您会收到类似 点击了是 的消息。
与原始 Discord API 的关键区别
| 您可能期望的 | OpenClaw 实际使用的 |
|---|
| type: container 包装器 | container: { accentColor: ... } 配置对象 |
| type: text_display |
块中的 type: text |
| 带嵌套组件的 type: action_row | 带 buttons 或 select 的 type: actions |
| 按钮上的手动 custom_id | 自动生成 — 只需设置 label 和 style |
| accent_color: 0x3498db | accentColor: #3498db(优先使用十六进制字符串) |
| type: string_select | actions 块内的 select: { type: string, ... } |
块类型摘要
文本 + 可选的缩略图/按钮 |
components.md |
| separator | 分隔线 |
components.md |
| actions | 按钮或选择菜单 |
components.md |
| media-gallery | 图片画廊 |
components.md |
| file | 文件附件 |
components.md |
处理交互
当用户点击按钮或选择选项时,OpenClaw 将其作为普通入站消息传递:
- - 按钮点击 → 点击了是
- 选择 → 从选择一个选项中选择了 option_a
无需特殊的回调处理 — 只需读取传入的消息文本。参见 handling.md 了解模式。
重要规则
- - 无需 custom_id — OpenClaw 自动为所有交互元素生成唯一 ID
- 无需 embeds — Components v2 和 embeds 不能共存于同一条消息中
- reusable: true — 设置此选项以允许按钮/选择菜单被多次点击
- allowedUsers — 可选地限制谁可以点击按钮(Discord 用户 ID 数组)
- Actions 块 — 必须包含 buttons 或 select 其中之一,不能同时包含两者
- 每个 actions 块最多 5 个按钮,每个 actions 块最多 1 个选择菜单
示例
参见 references/examples.md 了解完整场景:
- - 是/否确认
- 代理/选项选择
- 带操作的状态卡片
- 模态框表单收集
- 多步骤工作流