diff --git a/api/interaction.go b/api/interaction.go index 54442f3..d8d8bd6 100644 --- a/api/interaction.go +++ b/api/interaction.go @@ -24,6 +24,7 @@ const ( DeferredMessageInteractionWithSource DeferredMessageUpdate UpdateMessage + AutocompleteResult ) // InteractionResponseFlags implements flags for an @@ -72,6 +73,11 @@ type InteractionResponseData struct { // Files represents a list of files to upload. This will not be // JSON-encoded and will only be available through WriteMultipart. Files []sendpart.File `json:"-"` + + // Choices are the results to display on autocomplete interaction events. + // + // During all other events, this should not be provided. + Choices *[]AutocompleteChoice `json:"choices"` } // NeedsMultipart returns true if the InteractionResponseData has files. @@ -83,6 +89,13 @@ func (d InteractionResponseData) WriteMultipart(body *multipart.Writer) error { return sendpart.Write(body, d, d.Files) } +// AutocompleteChoice is the choice in ApplicationCommandAutocompleteResult in +// the official documentation. +type AutocompleteChoice struct { + Name string `json:"name"` + Value string `json:"value"` +} + // RespondInteraction responds to an incoming interaction. It is also known as // an "interaction callback". func (c *Client) RespondInteraction( @@ -129,7 +142,7 @@ func (c *Client) RespondInteraction( } } - var URL = EndpointInteractions + id.String() + "/" + token + "/callback" + URL := EndpointInteractions + id.String() + "/" + token + "/callback" return sendpart.POST(c.Client, resp, nil, URL) } diff --git a/discord/application.go b/discord/application.go index 25f8ab5..95453be 100644 --- a/discord/application.go +++ b/discord/application.go @@ -181,12 +181,15 @@ func (c Command) CreatedAt() time.Time { } type CommandOption struct { - Type CommandOptionType `json:"type"` - Name string `json:"name"` - Description string `json:"description"` - Required bool `json:"required"` - Choices []CommandOptionChoice `json:"choices,omitempty"` - Options []CommandOption `json:"options,omitempty"` + Type CommandOptionType `json:"type"` + Name string `json:"name"` + Description string `json:"description"` + Required bool `json:"required"` + + // Choices cannot be present if Autocomplete is true. + Choices []CommandOptionChoice `json:"choices,omitempty"` + Autocomplete bool `json:"autocomplete"` + Options []CommandOption `json:"options,omitempty"` // If this option is a channel type, the channels shown will be restricted to these types ChannelTypes []ChannelType `json:"-"` diff --git a/discord/interaction.go b/discord/interaction.go index 8e999ed..e85b02c 100644 --- a/discord/interaction.go +++ b/discord/interaction.go @@ -45,6 +45,8 @@ func (i *Interaction) UnmarshalJSON(p []byte) error { i.Data = &ComponentInteractionData{} case CommandInteraction: i.Data = &CommandInteractionData{} + case AutocompleteInteraction: + i.Data = &AutocompleteInteractionData{} default: i.Data = &UnknownInteractionData{typ: v.Type} } @@ -58,6 +60,7 @@ const ( PingInteraction InteractionType = iota + 1 CommandInteraction ComponentInteraction + AutocompleteInteraction ) // InteractionData holds the data of an interaction. @@ -87,6 +90,27 @@ func (*CommandInteractionData) Type() InteractionType { return CommandInteraction } +type AutocompleteInteractionData struct { + ID CommandID `json:"id"` + + // Name of command autocomplete is triggered for. + Name string `json:"name"` + CommandType CommandType `json:"type"` + Version string `json:"version"` + Options []AutocompleteCommandOption `json:"options"` +} + +type AutocompleteCommandOption struct { + Type CommandOptionType `json:"type"` + Name string `json:"name"` + Value string `json:"value"` + Focused bool `json:"focused"` +} + +func (*AutocompleteInteractionData) Type() InteractionType { + return AutocompleteInteraction +} + type UnknownInteractionData struct { json.Raw typ InteractionType