Skip to content

Commit

Permalink
document autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
devsnek committed Oct 25, 2021
1 parent 4967eca commit f62596f
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 23 deletions.
55 changes: 45 additions & 10 deletions docs/interactions/Application_Commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,21 @@ Application commands are commands that an application can register to Discord. T
> warn
> Required `options` must be listed before optional options
| Field | Type | Description |
| ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| type | one of [application command option type](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-type) | the type of option |
| name | string | [1-32 character name](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-naming) |
| description | string | 1-100 character description |
| required? | boolean | if the parameter is required or optional--default `false` |
| choices? | array of [application command option choice](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-choice-structure) | choices for `STRING`, `INTEGER`, and `NUMBER` types for the user to pick from, max 25 |
| options? | array of [application command option](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-structure) | if the option is a subcommand or subcommand group type, this nested options will be the parameters |
| channel_types? | array of [channel types](#DOCS_RESOURCES_CHANNEL/channel-object-channel-types) | if the option is a channel type, the channels shown will be restricted to these types |
| Field | Type | Description |
| ----------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------- |
| type | one of [application command option type](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-type) | the type of option |
| name | string | [1-32 character name](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-naming) |
| description | string | 1-100 character description |
| required? | boolean | if the parameter is required or optional--default `false` |
| choices? | array of [application command option choice](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-choice-structure) | choices for `STRING`, `INTEGER`, and `NUMBER` types for the user to pick from, max 25 |
| autocomplete? \* | boolean | enable autocomplete interactions for this option |
| options? | array of [application command option](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-structure) | if the option is a subcommand or subcommand group type, this nested options will be the parameters |
| channel_types? | array of [channel types](#DOCS_RESOURCES_CHANNEL/channel-object-channel-types) | if the option is a channel type, the channels shown will be restricted to these types |

\* `autocomplete` may not be set to true if `choices` are present.

> note
> Options using `autocomplete` are not confined to only use choices given by the application.
###### Application Command Option Type

Expand Down Expand Up @@ -79,12 +85,13 @@ All options have names, and an option can either be a parameter and input value-

`value` and `options` are mutually exclusive.

| Field | Type | Description |
| Field | Type | Description |
| -------- |--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| name | string | the name of the parameter |
| type | integer | value of [application command option type](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-type) |
| value? | [application command option type](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-option-type) | the value of the pair |
| options? | array of [application command interaction data option](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-object-application-command-interaction-data-option-structure) | present if this option is a group or subcommand |
| focused? | boolean | true if this option is the currently focused option for autocomplete |

## Authorizing Your Application

Expand Down Expand Up @@ -841,6 +848,34 @@ When someone uses a message command, your application will receive an interactio
}
```

## Autocomplete

Autocomplete interactions allow application command option values to be completed by the application as the user types out a command invocation.

> info
> Autocomplete choices are only suggestions, and the user may still fill in whatever value they choose.
Implementing autocomplete is quite simple.

```json
{
"type": 4,
"data": {
"id": "816437322781949972",
"name": "airhorn",
"type": 1,
"version": "847194950382780532",
"options": [
{
"type": 3,
"name": "variant",
"value": "data a user is typ",
"focused": true
}
]
}
}
```

### Endpoints

Expand Down
34 changes: 21 additions & 13 deletions docs/interactions/Receiving_and_Responding.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ For [Message Components](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/) it includes ide

###### Interaction Type

| Name | Value |
| ------------------- | ----- |
| PING | 1 |
| APPLICATION_COMMAND | 2 |
| MESSAGE_COMPONENT | 3 |
| Name | Value |
| -------------------------------- | ----- |
| PING | 1 |
| APPLICATION_COMMAND | 2 |
| MESSAGE_COMPONENT | 3 |
| APPLICATION_COMMAND_AUTOCOMPLETE | 4 |

###### Interaction Data Structure

Expand Down Expand Up @@ -158,17 +159,18 @@ There are a number of ways you can respond to an interaction:

###### Interaction Callback Type

| Name | Value | Description |
| ------------------------------------ | ----- | ------------------------------------------------------------------------------------------------------------- |
| PONG | 1 | ACK a `Ping` |
| CHANNEL_MESSAGE_WITH_SOURCE | 4 | respond to an interaction with a message |
| DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE | 5 | ACK an interaction and edit a response later, the user sees a loading state |
| DEFERRED_UPDATE_MESSAGE\* | 6 | for components, ACK an interaction and edit the original message later; the user does not see a loading state |
| UPDATE_MESSAGE\* | 7 | for components, edit the message the component was attached to |
| Name | Value | Description |
| --------------------------------------- | ----- | ------------------------------------------------------------------------------------------------------------- |
| PONG | 1 | ACK a `Ping` |
| CHANNEL_MESSAGE_WITH_SOURCE | 4 | respond to an interaction with a message |
| DEFERRED_CHANNEL_MESSAGE_WITH_SOURCE | 5 | ACK an interaction and edit a response later, the user sees a loading state |
| DEFERRED_UPDATE_MESSAGE\* | 6 | for components, ACK an interaction and edit the original message later; the user does not see a loading state |
| UPDATE_MESSAGE\* | 7 | for components, edit the message the component was attached to |
| APPLICATION_COMMAND_AUTOCOMPLETE_RESULT | 8 | respond to an interaction autocomplete interaction with suggested choices |

\* Only valid for [component-based](#DOCS_INTERACTIONS_MESSAGE_COMPONENTS/) interactions

###### Interaction Callback Data Structure
###### Interaction Callback Data Structure (Messages)

Not all message fields are currently supported.

Expand All @@ -184,6 +186,12 @@ Not all message fields are currently supported.

\* See [Uploading Files](#DOCS_REFERENCE/uploading-files) for details.

###### Interaction Callback Data Structure (Autocomplete)

| Name | Type | Description |
| -------- | ------------------------------------------------------------------------------------------------------- | ---------------------------------------- |
| choices | array of [choices](#DOCS_INTERACTIONS_APPLICATION_COMMANDS/application-command-option-choice-structure) | autocomplete choices (max of 25 choices) |

###### Interaction Callback Data Flags

| Name | Value | Description |
Expand Down

0 comments on commit f62596f

Please sign in to comment.