Skip to content

Commit

Permalink
Add event for autocomplete interaction (discord-net#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
marens101 committed Oct 2, 2021
1 parent c073db1 commit 34748c8
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Discord.Net.WebSocket/BaseSocketClient.Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@ public event Func<SocketGuildChannel, string, Task> InviteDeleted

#region Interactions
/// <summary>
/// Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands.
/// Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands, autocompletes.
/// </summary>
/// <remarks>
/// <para>
Expand Down Expand Up @@ -535,6 +535,15 @@ public event Func<SocketMessageCommand, Task> MessageCommandExecuted
remove => _messageCommandExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketMessageCommand, Task>> _messageCommandExecuted = new AsyncEvent<Func<SocketMessageCommand, Task>>();
/// <summary>
/// Fired when an autocomplete is used and its interaction is received.
/// </summary>
public event Func<SocketAutocompleteInteraction, Task> AutocompleteExecuted
{
add => _autocompleteExecuted.Add(value);
remove => _autocompleteExecuted.Remove(value);
}
internal readonly AsyncEvent<Func<SocketAutocompleteInteraction, Task>> _autocompleteExecuted = new AsyncEvent<Func<SocketAutocompleteInteraction, Task>>();

/// <summary>
/// Fired when a guild application command is created.
Expand Down
5 changes: 5 additions & 0 deletions src/Discord.Net.WebSocket/Discord.Net.WebSocket.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/Discord.Net.WebSocket/DiscordShardedClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ private void RegisterEvents(DiscordSocketClient client, bool isPrimary)
client.SlashCommandExecuted += (arg) => _slashCommandExecuted.InvokeAsync(arg);
client.UserCommandExecuted += (arg) => _userCommandExecuted.InvokeAsync(arg);
client.MessageCommandExecuted += (arg) => _messageCommandExecuted.InvokeAsync(arg);
client.AutocompleteExecuted += (arg) => _autocompleteExecuted.InvokeAsync(arg);

client.ThreadUpdated += (thread1, thread2) => _threadUpdated.InvokeAsync(thread1, thread2);
client.ThreadCreated += (thread) => _threadCreated.InvokeAsync(thread);
Expand Down
3 changes: 3 additions & 0 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,9 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
case SocketMessageCommand messageCommand:
await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false);
break;
case SocketAutocompleteInteraction autocomplete:
await TimedInvokeAsync(_autocompleteExecuted, nameof(AutocompleteExecuted), autocomplete).ConfigureAwait(false);
break;
}
}
else
Expand Down

0 comments on commit 34748c8

Please sign in to comment.