-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathInteractionHandler.cs
38 lines (33 loc) · 1.05 KB
/
InteractionHandler.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
using System.Reflection;
using Discord.Interactions;
using Discord.WebSocket;
namespace JukeBox;
public class InteractionHandler
{
private readonly DiscordSocketClient _client;
private readonly InteractionService _slashCommands;
private readonly IServiceProvider _services;
public InteractionHandler(DiscordSocketClient client, InteractionService slashCommands, IServiceProvider services)
{
_client = client;
_slashCommands = slashCommands;
_services = services;
}
public async Task InitializeAsync()
{
_client.InteractionCreated += HandleInteraction;
await _slashCommands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
}
private async Task HandleInteraction(SocketInteraction arg)
{
try
{
var context = new SocketInteractionContext(_client, arg);
await _slashCommands.ExecuteCommandAsync(context, _services);
}
catch (Exception exception)
{
Console.WriteLine(exception.ToString());
}
}
}