diff --git a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
index 6aa18db23..e58589c08 100644
--- a/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
+++ b/src/Discord.Net.WebSocket/Entities/Interaction/Slash Commands/SocketAutocompleteInteraction.cs
@@ -18,6 +18,9 @@ namespace Discord.WebSocket
///
public new SocketAutocompleteInteractionData Data { get; }
+ internal override bool _hasResponded { get; set; }
+ private object _lock = new object();
+
internal SocketAutocompleteInteraction(DiscordSocketClient client, Model model, ISocketMessageChannel channel)
: base(client, model.Id, channel)
{
@@ -50,8 +53,25 @@ namespace Discord.WebSocket
///
/// A task that represents the asynchronous operation of responding to this interaction.
///
- public Task RespondAsync(IEnumerable result, RequestOptions options = null)
- => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options);
+ public async Task RespondAsync(IEnumerable 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;
+ }
+ }
///
/// 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.
///
public Task RespondAsync(RequestOptions options = null, params AutocompleteResult[] result)
- => InteractionHelper.SendAutocompleteResultAsync(Discord, result, Id, Token, options);
+ => RespondAsync(result, options);
///
[Obsolete("Autocomplete interactions cannot be deferred!", true)]