惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Last Week in AI
Last Week in AI
大猫的无限游戏
大猫的无限游戏
博客园 - Franky
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
爱范儿
爱范儿
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
博客园 - 叶小钗
博客园_首页
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
宝玉的分享
宝玉的分享
V
V2EX
V
Visual Studio Blog
博客园 - 三生石上(FineUI控件)
S
SegmentFault 最新的问题
量子位
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Apple Machine Learning Research
Apple Machine Learning Research
美团技术团队

Chat SDK Documentation

History | Chat SDK History | Chat SDK List a vendor-official adapter | Chat SDK Approvals | Chat SDK Vercel Connect | Chat SDK Teams Low-Level APIs | Chat SDK CLI | Chat SDK Platform Adapters | Chat SDK State Adapters | Chat SDK Cards | Chat SDK Getting Started | Chat SDK Introduction | Chat SDK Modals | Chat SDK Slack Low-Level APIs | Chat SDK Streaming | Chat SDK Testing | Chat SDK Overview | Chat SDK toAiMessages | Chat SDK Cards | Chat SDK Overview | Chat SDK Markdown | Chat SDK Modals | Chat SDK AI SDK Tools | Chat SDK Types | Chat SDK Message Subject | Chat SDK Conversation History | Chat SDK Transcripts | Chat SDK Slack bot with Next.js and Redis Actions | Chat SDK Direct Messages | Chat SDK
Slash Commands | Chat SDK
Vercel · 2026-04-06 · via Chat SDK Documentation

Handle slash command invocations and respond with messages or modals.

Slash commands let users invoke your bot with /command syntax. Register handlers with onSlashCommand to respond.

Slash commands are supported on Slack and Discord.

bot.onSlashCommand("/status", async (event) => {
  await event.channel.post("All systems operational!");
});
bot.onSlashCommand(["/help", "/info"], async (event) => {
  await event.channel.post(`You invoked ${event.command}`);
});

Register a handler without a command to catch all slash commands:

bot.onSlashCommand(async (event) => {
  console.log(`Command: ${event.command}, Args: ${event.text}`);
});

The event object passed to slash command handlers:

PropertyTypeDescription
commandstringThe command name (e.g., /status)
textstringArguments after the command
userAuthorThe user who invoked the command
channelChannelThe channel where the command was invoked
adapterAdapterThe platform adapter
triggerIdstring (optional)Platform trigger ID for opening modals
openModal(modal) => Promise<{ viewId: string } | undefined>Open a modal dialog
rawunknownPlatform-specific payload

Use event.channel to post messages:

bot.onSlashCommand("/greet", async (event) => {
  // Public message to the channel
  await event.channel.post(`Hello, ${event.user.fullName}!`);

  // Ephemeral message (only visible to the user)
  await event.channel.postEphemeral(
    event.user,
    "This message is just for you!",
    { fallbackToDM: false }
  );
});

Use event.openModal() to open a modal in response to a slash command:

import { Modal, TextInput, Select, SelectOption } from "chat";

bot.onSlashCommand("/feedback", async (event) => {
  const result = await event.openModal(
    <Modal callbackId="feedback_form" title="Send Feedback" submitLabel="Send">
      <TextInput id="message" label="Your Feedback" multiline />
      <Select id="category" label="Category">
        <SelectOption label="Bug" value="bug" />
        <SelectOption label="Feature" value="feature" />
      </Select>
    </Modal>
  );

  if (!result) {
    await event.channel.post("Couldn't open the feedback form. Please try again.");
  }
});

When a modal is opened from a slash command, the submit handler receives relatedChannel instead of relatedThread. Use this to post back to the channel where the command was invoked.

bot.onModalSubmit("feedback_form", async (event) => {
  const { message, category } = event.values;

  // Post to the channel where the slash command was invoked
  if (event.relatedChannel) {
    await event.relatedChannel.post(`Feedback received! Category: ${category}`);
  }
});

Discord slash commands are received via HTTP Interactions — no Gateway connection is needed. The adapter automatically sends a deferred response to Discord, then resolves it when your handler calls event.channel.post().

Subcommands

Discord supports subcommand groups and subcommands. The adapter flattens these into the event.command path:

Discord commandevent.commandevent.text
/status/status""
/project create --name="Acme"/project createAcme
/project issue list --status="open"/project issue listopen

For full option details (names, types), use event.raw to access the original Discord interaction payload.

Registering commands with Discord

You need to register slash commands with the Discord API before they appear in the client. The Chat SDK handles incoming commands but does not register them for you.