@@ -457,7 +457,7 @@ namespace Discord.WebSocket | |||||
//Interactions | //Interactions | ||||
/// <summary> | /// <summary> | ||||
/// Fired when an Interaction is created. | |||||
/// Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands. | |||||
/// </summary> | /// </summary> | ||||
/// <remarks> | /// <remarks> | ||||
/// <para> | /// <para> | ||||
@@ -475,6 +475,55 @@ namespace Discord.WebSocket | |||||
} | } | ||||
internal readonly AsyncEvent<Func<SocketInteraction, Task>> _interactionCreatedEvent = new AsyncEvent<Func<SocketInteraction, Task>>(); | internal readonly AsyncEvent<Func<SocketInteraction, Task>> _interactionCreatedEvent = new AsyncEvent<Func<SocketInteraction, Task>>(); | ||||
/// <summary> | |||||
/// Fired when a button is clicked and its interaction is received. | |||||
/// </summary> | |||||
public event Func<SocketMessageComponent, Task> ButtonExecuted | |||||
{ | |||||
add => _buttonExecuted.Add(value); | |||||
remove => _buttonExecuted.Remove(value); | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketMessageComponent, Task>> _buttonExecuted = new AsyncEvent<Func<SocketMessageComponent, Task>>(); | |||||
/// <summary> | |||||
/// Fired when a select menu is used and its interaction is received. | |||||
/// </summary> | |||||
public event Func<SocketMessageComponent, Task> SelectMenuExecuted | |||||
{ | |||||
add => _selectMenuExecuted.Add(value); | |||||
remove => _selectMenuExecuted.Remove(value); | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketMessageComponent, Task>> _selectMenuExecuted = new AsyncEvent<Func<SocketMessageComponent, Task>>(); | |||||
/// <summary> | |||||
/// Fired when a slash command is used and its interaction is received. | |||||
/// </summary> | |||||
public event Func<SocketSlashCommand, Task> SlashCommandExecuted | |||||
{ | |||||
add => _slashCommandExecuted.Add(value); | |||||
remove => _slashCommandExecuted.Remove(value); | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketSlashCommand, Task>> _slashCommandExecuted = new AsyncEvent<Func<SocketSlashCommand, Task>>(); | |||||
/// <summary> | |||||
/// Fired when a user command is used and its interaction is received. | |||||
/// </summary> | |||||
public event Func<SocketUserCommand, Task> UserCommandExecuted | |||||
{ | |||||
add => _userCommandExecuted.Add(value); | |||||
remove => _userCommandExecuted.Remove(value); | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketUserCommand, Task>> _userCommandExecuted = new AsyncEvent<Func<SocketUserCommand, Task>>(); | |||||
/// <summary> | |||||
/// Fired when a message command is used and its interaction is received. | |||||
/// </summary> | |||||
public event Func<SocketMessageCommand, Task> MessageCommandExecuted | |||||
{ | |||||
add => _messageCommandExecuted.Add(value); | |||||
remove => _messageCommandExecuted.Remove(value); | |||||
} | |||||
internal readonly AsyncEvent<Func<SocketMessageCommand, Task>> _messageCommandExecuted = new AsyncEvent<Func<SocketMessageCommand, Task>>(); | |||||
/// <summary> | /// <summary> | ||||
/// Fired when a guild application command is created. | /// Fired when a guild application command is created. | ||||
///</summary> | ///</summary> | ||||
@@ -709,7 +709,7 @@ | |||||
</member> | </member> | ||||
<member name="E:Discord.WebSocket.BaseSocketClient.InteractionCreated"> | <member name="E:Discord.WebSocket.BaseSocketClient.InteractionCreated"> | ||||
<summary> | <summary> | ||||
Fired when an Interaction is created. | |||||
Fired when an Interaction is created. This event covers all types of interactions including but not limited to: buttons, select menus, slash commands. | |||||
</summary> | </summary> | ||||
<remarks> | <remarks> | ||||
<para> | <para> | ||||
@@ -721,6 +721,31 @@ | |||||
</para> | </para> | ||||
</remarks> | </remarks> | ||||
</member> | </member> | ||||
<member name="E:Discord.WebSocket.BaseSocketClient.ButtonExecuted"> | |||||
<summary> | |||||
Fired when a button is clicked and its interaction is received. | |||||
</summary> | |||||
</member> | |||||
<member name="E:Discord.WebSocket.BaseSocketClient.SelectMenuExecuted"> | |||||
<summary> | |||||
Fired when a select menu is used and its interaction is received. | |||||
</summary> | |||||
</member> | |||||
<member name="E:Discord.WebSocket.BaseSocketClient.SlashCommandExecuted"> | |||||
<summary> | |||||
Fired when a slash command is used and its interaction is received. | |||||
</summary> | |||||
</member> | |||||
<member name="E:Discord.WebSocket.BaseSocketClient.UserCommandExecuted"> | |||||
<summary> | |||||
Fired when a user command is used and its interaction is received. | |||||
</summary> | |||||
</member> | |||||
<member name="E:Discord.WebSocket.BaseSocketClient.MessageCommandExecuted"> | |||||
<summary> | |||||
Fired when a message command is used and its interaction is received. | |||||
</summary> | |||||
</member> | |||||
<member name="E:Discord.WebSocket.BaseSocketClient.ApplicationCommandCreated"> | <member name="E:Discord.WebSocket.BaseSocketClient.ApplicationCommandCreated"> | ||||
<summary> | <summary> | ||||
Fired when a guild application command is created. | Fired when a guild application command is created. | ||||
@@ -456,6 +456,11 @@ namespace Discord.WebSocket | |||||
client.InviteDeleted += (channel, invite) => _inviteDeletedEvent.InvokeAsync(channel, invite); | client.InviteDeleted += (channel, invite) => _inviteDeletedEvent.InvokeAsync(channel, invite); | ||||
client.InteractionCreated += (interaction) => _interactionCreatedEvent.InvokeAsync(interaction); | client.InteractionCreated += (interaction) => _interactionCreatedEvent.InvokeAsync(interaction); | ||||
client.ButtonExecuted += (arg) => _buttonExecuted.InvokeAsync(arg); | |||||
client.SelectMenuExecuted += (arg) => _selectMenuExecuted.InvokeAsync(arg); | |||||
client.SlashCommandExecuted += (arg) => _slashCommandExecuted.InvokeAsync(arg); | |||||
client.UserCommandExecuted += (arg) => _userCommandExecuted.InvokeAsync(arg); | |||||
client.MessageCommandExecuted += (arg) => _messageCommandExecuted.InvokeAsync(arg); | |||||
client.ThreadUpdated += (thread1, thread2) => _threadUpdated.InvokeAsync(thread1, thread2); | client.ThreadUpdated += (thread1, thread2) => _threadUpdated.InvokeAsync(thread1, thread2); | ||||
client.ThreadCreated += (thread) => _threadCreated.InvokeAsync(thread); | client.ThreadCreated += (thread) => _threadCreated.InvokeAsync(thread); | ||||
@@ -2090,6 +2090,25 @@ namespace Discord.WebSocket | |||||
await interaction.DeferAsync().ConfigureAwait(false); | await interaction.DeferAsync().ConfigureAwait(false); | ||||
await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false); | await TimedInvokeAsync(_interactionCreatedEvent, nameof(InteractionCreated), interaction).ConfigureAwait(false); | ||||
switch (interaction) | |||||
{ | |||||
case SocketSlashCommand slashCommand: | |||||
await TimedInvokeAsync(_slashCommandExecuted, nameof(SlashCommandExecuted), slashCommand).ConfigureAwait(false); | |||||
break; | |||||
case SocketMessageComponent messageComponent: | |||||
if(messageComponent.Data.Type == ComponentType.SelectMenu) | |||||
await TimedInvokeAsync(_selectMenuExecuted, nameof(SelectMenuExecuted), messageComponent).ConfigureAwait(false); | |||||
if(messageComponent.Data.Type == ComponentType.Button) | |||||
await TimedInvokeAsync(_buttonExecuted, nameof(ButtonExecuted), messageComponent).ConfigureAwait(false); | |||||
break; | |||||
case SocketUserCommand userCommand: | |||||
await TimedInvokeAsync(_userCommandExecuted, nameof(UserCommandExecuted), userCommand).ConfigureAwait(false); | |||||
break; | |||||
case SocketMessageCommand messageCommand: | |||||
await TimedInvokeAsync(_messageCommandExecuted, nameof(MessageCommandExecuted), messageCommand).ConfigureAwait(false); | |||||
break; | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||