| @@ -18,6 +18,9 @@ namespace Discord.WebSocket | |||||
| /// </summary> | /// </summary> | ||||
| public new SocketAutocompleteInteractionData Data { get; } | public new SocketAutocompleteInteractionData Data { get; } | ||||
| internal override bool _hasResponded { get; set; } | |||||
| private object _lock = new object(); | |||||
| internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel) | internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel) | ||||
| : base(client, model.Id, channel) | : base(client, model.Id, channel) | ||||
| { | { | ||||
| @@ -50,8 +53,25 @@ namespace Discord.WebSocket | |||||
| /// <returns> | /// <returns> | ||||
| /// A task that represents the asynchronous operation of responding to this interaction. | /// A task that represents the asynchronous operation of responding to this interaction. | ||||
| /// </returns> | /// </returns> | ||||
| public Task RespondAsync(IEnumerable<AutocompleteResult> result, RequestOptions options = null) | |||||
| => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options); | |||||
| public async Task RespondAsync(IEnumerable<AutocompleteResult> result, RequestOptions options = null) | |||||
| { | |||||
| if (!InteractionHelper.CanSendResponse(this)) | |||||
| throw new TimeoutException($"Cannot respond to an interaction after {InteractionHelper.ResponseTimeLimit} seconds!"); | |||||
| lock (_lock) | |||||
| { | |||||
| if (_hasResponded) | |||||
| { | |||||
| throw new InvalidOperationException("Cannot respond twice to the same interaction"); | |||||
| } | |||||
| } | |||||
| await InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options).ConfigureAwait(false); | |||||
| lock (_lock) | |||||
| { | |||||
| _hasResponded = true; | |||||
| } | |||||
| } | |||||
| /// <summary> | /// <summary> | ||||
| /// Responds to this interaction with a set of choices. | /// Responds to this interaction with a set of choices. | ||||
| @@ -68,7 +88,7 @@ namespace Discord.WebSocket | |||||
| /// A task that represents the asynchronous operation of responding to this interaction. | /// A task that represents the asynchronous operation of responding to this interaction. | ||||
| /// </returns> | /// </returns> | ||||
| public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result) | public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result) | ||||
| => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options); | |||||
| => RespondAsync(result, options); | |||||
| /// <inheritdoc/> | /// <inheritdoc/> | ||||
| [Obsolete("Autocomplete interactions cannot be deferred!", true)] | [Obsolete("Autocomplete interactions cannot be deferred!", true)] | ||||