# Interactions

> Answering an interaction with its callback (a message, an update of the component’s message, a modal), and the webhook routes that use the interaction’s token for follow-ups and for reading, editing and deleting the answers. Every field, the time limits and the errors.

## Before you read

These routes answer an [interaction](https://docs.klang.gg/bots/reference/objects/#interaction), the event your bot
gets when someone uses one of its commands, presses one of its buttons, chooses in one of its
menus or sends one of its modals. The guides are
[Responding to interactions](https://docs.klang.gg/bots/interactions/), [Buttons, menus and layouts](https://docs.klang.gg/bots/components/)
and [Modals](https://docs.klang.gg/bots/modals/).

- **No bot token.** The interaction’s `token`, in the path, is the key. Libraries send these
  requests without an `Authorization` header.
- **Time limits.** The callback has to come within 3 seconds of the interaction. The token works
  for 15 minutes.
- **Rate limits.** None of these routes count against the bot’s global limit. The webhook routes
  share a bucket per interaction, `interaction-webhook`: 5 requests every 2 seconds. A request
  with an ID or token that doesn’t match counts against the global limit of its IP address.
- **JSON or a form.** The callback and the webhook routes also take `multipart/form-data` with
  `payload_json` and [files](https://docs.klang.gg/bots/files/), in ephemeral messages too.

## Answer an interaction

```http
POST /interactions/{interaction.id}/{interaction.token}/callback
```

The first answer. Its body has a `type` and, for most types, `data`:

| `type` | What it does                                                      | `data`                                                          |
| ------ | ----------------------------------------------------------------- | --------------------------------------------------------------- |
| `4`    | Posts a message as the answer.                                    | A [message](https://docs.klang.gg/bots/reference/interactions/#the-message-body). Required.                       |
| `5`    | Defers: the person sees that the bot is thinking.                 | Optional. `flags: 64` makes the message that follows ephemeral. |
| `6`    | Defers an update of the component’s message: nothing changes yet. | None.                                                           |
| `7`    | Updates the component’s message.                                  | [An edit](https://docs.klang.gg/bots/reference/interactions/#update-the-message). Optional.                       |
| `8`    | Suggestions for an autocomplete.                                  | `choices`: up to 25. Required.                                  |
| `9`    | Opens a modal for the person.                                     | [A modal](https://docs.klang.gg/bots/reference/interactions/#open-a-modal). Required.                             |

Which types each interaction takes:

| Interaction                    | Callback types                                                |
| ------------------------------ | ------------------------------------------------------------- |
| `2`, a command                 | `4`, `5` and `9`                                              |
| `3`, a button or a select menu | `4`, `5`, `6`, `7` and `9`                                    |
| `4`, an autocomplete           | `8`                                                           |
| `5`, a submitted modal         | `4` and `5`; also `6` and `7` if a component opened the modal |

Any other type answers `50035` on `type`, listing the ones that fit, and the interaction can
still be answered. `1` only answers the check of an [HTTP interactions](https://docs.klang.gg/bots/http-interactions/)
URL, and `10` and `12` (paid apps and activities) don’t exist in Klang.

Each choice of `8` is `{ name, name_localizations?, value }`: a `name` of 1 to 100 characters
and a `value` that’s text of up to 100 characters or a number. People read the name in their
language when `name_localizations` has it. Locales Discord doesn’t have are dropped.

| Query           | Type    | Notes                                                                                   |
| --------------- | ------- | --------------------------------------------------------------------------------------- |
| `with_response` | boolean | With `true` (or `1`), the answer is `200` and says what was created. Without it, `204`. |

`{"type": 4, "data": {"content": "North Pier: high tide at 06:42 and 18:57 (4.1 m)."}}` with
`?with_response=true`:

```json
{
  "interaction": {
    "id": "1575120625984638976",
    "type": 2,
    "response_message_loading": false,
    "response_message_ephemeral": false,
    "response_message_id": "1575120626244685824"
  },
  "resource": {
    "type": 4,
    "message": {
      "id": "1575120626244685824",
      "channel_id": "1575120255329800194",
      "type": 20,
      "author": {
        "id": "1575120256797806592",
        "username": "lighthouse",
        "discriminator": "0",
        "global_name": "Lighthouse",
        "avatar": null,
        "banner": null,
        "accent_color": null,
        "public_flags": 0,
        "bot": true
      },
      "content": "North Pier: high tide at 06:42 and 18:57 (4.1 m).",
      "timestamp": "2026-11-25T12:07:01.622Z",
      "edited_timestamp": null,
      "tts": false,
      "mention_everyone": false,
      "mentions": [],
      "mention_roles": [],
      "attachments": [],
      "embeds": [],
      "pinned": false,
      "flags": 0,
      "components": [],
      "application_id": "1575120256797806592",
      "webhook_id": "1575120256797806592",
      "interaction_metadata": {
        "id": "1575120625984638976",
        "type": 2,
        "user": {
          "id": "1575120252091797504",
          "username": "leo",
          "discriminator": "0",
          "global_name": "Leo",
          "avatar": null,
          "banner": null,
          "accent_color": null,
          "public_flags": 0
        },
        "authorizing_integration_owners": { "0": "1575120255329800192" }
      },
      "interaction": {
        "id": "1575120625984638976",
        "type": 2,
        "name": "tide",
        "user": {
          "id": "1575120252091797504",
          "username": "leo",
          "discriminator": "0",
          "global_name": "Leo",
          "avatar": null,
          "banner": null,
          "accent_color": null,
          "public_flags": 0
        }
      }
    }
  }
}
```

`{"type": 5}` with `?with_response=true`. There’s no message yet, so no `response_message_id`:
in Klang, “thinking” is shown only to the person and isn’t a message.

```json
{
  "interaction": {
    "id": "1575120626479566848",
    "type": 2,
    "response_message_loading": true,
    "response_message_ephemeral": false
  },
  "resource": { "type": 5 }
}
```

A `7` that changed a role panel, with `?with_response=true` (the message is shortened). The
message is the component’s own:

```json
{
  "interaction": {
    "id": "1575619367957962752",
    "type": 3,
    "response_message_loading": false,
    "response_message_ephemeral": false,
    "response_message_id": "1575619367794384896"
  },
  "resource": {
    "type": 7,
    "message": {
      "id": "1575619367794384896",
      "type": 0,
      "content": "Pick your harbor roles: Leo is now a sailor. ⛵",
      "edited_timestamp": "2026-11-26T21:08:50.984Z"
    }
  }
}
```

A `6` has no message, and says so with `response_message_loading` and
`response_message_ephemeral` both `false` and no `response_message_id`. A `9` has only the
interaction’s `id` and `type`, and `resource` is `{ "type": 9 }`.

| Status | Code     | When                                                                                                                                                                                       |
| ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `400`  | `50035`  | A type that doesn’t fit the interaction, a field that’s wrong, a modal or components that break a [rule](https://docs.klang.gg/bots/reference/components/#errors), or files with a type other than `4` and `7`. |
| `400`  | `50006`  | A `4` with nothing to show.                                                                                                                                                                |
| `400`  | `40060`  | The interaction was already answered.                                                                                                                                                      |
| `400`  | `200000` | The server’s AutoMod blocked the message. You can try again within the 3 seconds.                                                                                                          |
| `404`  | `10062`  | No interaction with that ID and token, the 3 seconds are over, or the bot left the server.                                                                                                 |
| `404`  | `10003`  | The bot can no longer see the channel.                                                                                                                                                     |

```json
{ "code": 40060, "message": "Interaction has already been acknowledged." }
```

A `7` to a command:

```json
{
  "code": 50035,
  "message": "The request body isn’t valid.",
  "errors": {
    "type": {
      "_errors": [{ "code": "BASE_TYPE_CHOICES", "message": "Value must be one of {4, 5, 9}." }]
    }
  }
}
```

A callback that comes after the 3 seconds gets `10062`, and the person sees that the application
didn’t respond.

## The message body

What a `4` takes in `data`, and what follow-ups and edits take as their body:

| Field              | Type                                              | Notes                                                                                                                                                                                    |
| ------------------ | ------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `content`          | string                                            | Up to 4,000 characters.                                                                                                                                                                  |
| `embeds`           | array of [embeds](https://docs.klang.gg/bots/reference/objects/#embed) | Up to 10, as in [Send a message](https://docs.klang.gg/bots/reference/messages/#send-a-message).                                                                                                              |
| `allowed_mentions` | object                                            | As in [Send a message](https://docs.klang.gg/bots/reference/messages/#send-a-message).                                                                                                                        |
| `flags`            | integer                                           | `EPHEMERAL` (`1 << 6`): only the person sees it. `SUPPRESS_EMBEDS` (`1 << 2`): no link previews. `IS_COMPONENTS_V2` (`1 << 15`): the components are the message. Other bits are ignored. |
| `tts`              | boolean                                           | Accepted and ignored.                                                                                                                                                                    |
| `components`       | array                                             | [Components](https://docs.klang.gg/bots/reference/components/): action rows or, with `IS_COMPONENTS_V2`, layout components.                                                                                   |
| `attachments`      | array                                             | The files of the form: `id` (the `n` of `files[n]`), `filename`. See [Sending files](https://docs.klang.gg/bots/files/).                                                                                      |

A message needs `content` that isn’t blank, an embed, a component or a file; otherwise it
answers `50006`. With `IS_COMPONENTS_V2` it can’t have `content` or `embeds`. Its type is `20`
for a slash command, `23` for a user or message command, and `0` for a component or a modal. It
carries [`interaction_metadata`](https://docs.klang.gg/bots/reference/objects/#interaction-metadata).

The bot needs to see the channel, but not **Send messages**, and slow mode doesn’t apply. Messages
that aren’t ephemeral go through the server’s AutoMod.

**Ephemeral messages** aren’t stored. They reach only the person who used the command, for the
15 minutes of the interaction; their mentions don’t notify and their links get no preview. They
can have components and [files](https://docs.klang.gg/bots/files/#files-in-ephemeral-messages): Klang deletes those
files an hour after the command was used, or before if the message is deleted or an edit drops
them.

## Update the message

What a `7` takes in `data`, to change the message of the component that was pressed, or of the
component that opened the modal: the body of
[Edit a message](https://docs.klang.gg/bots/reference/messages/#edit-a-message). What you don’t send stays as it was.
`components: []` removes the components, and `attachments` says which files stay, as in an edit;
new [files](https://docs.klang.gg/bots/files/) go in the form. The edit goes through AutoMod like the bot’s other
messages. An ephemeral message is updated where it is.

After a `6` or a `7`, `@original` is that message, so `PATCH …/messages/@original` edits it.

## Open a modal

What a `9` takes in `data`: [the modal](https://docs.klang.gg/bots/reference/components/#the-modal), with its
`custom_id`, its `title` and 1 to 5 components. Klang shows it to the person who used the command
or pressed, and keeps it for the 15 minutes of the interaction. The person can send it once, and
the submission arrives as an interaction of type `5`. See [Modals](https://docs.klang.gg/bots/modals/).

A modal isn’t a message: after a `9`, the routes below answer `10015`.

## Messages with the interaction’s token

The routes of your app’s webhook, with the interaction’s token instead of a webhook’s. They work
for the 15 minutes of the token, after the first answer: before it, or for an autocomplete, they
answer `404` with `10015`.

| Route                                                                 | What it does                          |
| --------------------------------------------------------------------- | ------------------------------------- |
| `POST /webhooks/{app.id}/{interaction.token}`                         | Sends a follow-up.                    |
| `GET /webhooks/{app.id}/{interaction.token}`                          | Your app’s webhook.                   |
| `GET /webhooks/{app.id}/{interaction.token}/messages/{message.id}`    | One of the interaction’s messages.    |
| `PATCH /webhooks/{app.id}/{interaction.token}/messages/{message.id}`  | Edits one. What you don’t send stays. |
| `DELETE /webhooks/{app.id}/{interaction.token}/messages/{message.id}` | Deletes one. The answer is `204`.     |

`{message.id}` can be `@original`: the first answer or, after a `6` or a `7`, the message of the
component. Only the messages of this interaction count: any other answers `404` with `10008`.

### Send a follow-up

```http
POST /webhooks/{app.id}/{interaction.token}
```

A new message for the same interaction, with [the message body](https://docs.klang.gg/bots/reference/interactions/#the-message-body). It can be
ephemeral on its own. With `?wait=true` the answer is the message; without it, `204`.

After a `5`, the first follow-up becomes the answer: it takes the place of “thinking” and becomes
`@original`, ephemeral if the `5` asked for it.

An ephemeral follow-up (`"flags": 64`), sent with `?wait=true`:

```json
{
  "id": "1575120628685770752",
  "channel_id": "1575120255329800194",
  "type": 20,
  "author": {
    "id": "1575120256797806592",
    "username": "lighthouse",
    "discriminator": "0",
    "global_name": "Lighthouse",
    "avatar": null,
    "banner": null,
    "accent_color": null,
    "public_flags": 0,
    "bot": true
  },
  "content": "Tip: add `days` to see the rest of the week.",
  "timestamp": "2026-11-25T12:07:02.204Z",
  "edited_timestamp": null,
  "tts": false,
  "mention_everyone": false,
  "mentions": [],
  "mention_roles": [],
  "attachments": [],
  "embeds": [],
  "pinned": false,
  "flags": 64,
  "components": [],
  "application_id": "1575120256797806592",
  "webhook_id": "1575120256797806592",
  "interaction_metadata": {
    "id": "1575120626479566848",
    "type": 2,
    "user": {
      "id": "1575120252091797504",
      "username": "leo",
      "discriminator": "0",
      "global_name": "Leo",
      "avatar": null,
      "banner": null,
      "accent_color": null,
      "public_flags": 0
    },
    "authorizing_integration_owners": { "0": "1575120255329800192" }
  },
  "interaction": {
    "id": "1575120626479566848",
    "type": 2,
    "name": "tide",
    "user": {
      "id": "1575120252091797504",
      "username": "leo",
      "discriminator": "0",
      "global_name": "Leo",
      "avatar": null,
      "banner": null,
      "accent_color": null,
      "public_flags": 0
    }
  }
}
```

### Edit the answer

```http
PATCH /webhooks/{app.id}/{interaction.token}/messages/@original
```

Changes `content`, `embeds`, `allowed_mentions`, `components`, `attachments` or the flags of a
message (`SUPPRESS_EMBEDS`, and `IS_COMPONENTS_V2`, which can be set but never removed), and
answers with it. After a `5` with no message yet, it writes the answer instead: the person’s
“thinking” ends, and the message isn’t marked as edited.

### Delete the answer

```http
DELETE /webhooks/{app.id}/{interaction.token}/messages/@original
```

Deletes a message. After a `5` with no message yet, it ends the “thinking” without posting
anything.

### Your app’s webhook

`GET /webhooks/{app.id}/{interaction.token}` answers a webhook of type `3`, your app’s, as some
libraries read it:

```json
{
  "type": 3,
  "id": "1575120256797806592",
  "name": null,
  "avatar": null,
  "channel_id": "1575120255329800194",
  "guild_id": "1575120255329800192",
  "application_id": "1575120256797806592"
}
```

### Errors

| Status | Code     | When                                                                                                                 |
| ------ | -------- | -------------------------------------------------------------------------------------------------------------------- |
| `400`  | `50035`  | A field is wrong.                                                                                                    |
| `400`  | `50006`  | A message with nothing to show.                                                                                      |
| `400`  | `200000` | The server’s AutoMod blocked the message.                                                                            |
| `404`  | `10015`  | The token isn’t valid, is older than 15 minutes, belongs to another app, or the interaction has no first answer yet. |
| `404`  | `10008`  | The message isn’t one of this interaction’s, or `@original` before the deferred answer has its message.              |
| `429`  | —        | More than 5 requests in 2 seconds for this interaction.                                                              |

```json
{ "code": 10015, "message": "Unknown Webhook" }
```

The responses of these routes carry the rate limit headers of the interaction’s bucket:

```http
HTTP/1.1 200 OK
Content-Type: application/json
X-RateLimit-Bucket: ee4c55a78563d0102d42170e0e7c598d
X-RateLimit-Limit: 5
X-RateLimit-Remaining: 3
X-RateLimit-Reset: 1795608422.970
X-RateLimit-Reset-After: 0.770
```
