-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCommandHandler.cs
More file actions
48 lines (36 loc) · 1.26 KB
/
CommandHandler.cs
File metadata and controls
48 lines (36 loc) · 1.26 KB
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
39
40
41
42
43
44
45
46
47
48
using Discord.Commands;
using Discord.WebSocket;
using System.Reflection;
using System.Threading.Tasks;
using KillianBot.Services;
namespace KillianBot
{
public class CommandHandler
{
private DiscordSocketClient _client;
private CommandService _service;
private char cmdLetter = Config.config.CommandLetter;
public CommandHandler(DiscordSocketClient client)
{
_client = client;
_service = new CommandService();
_service.AddModulesAsync(Assembly.GetEntryAssembly(), null);
_client.MessageReceived += HandleCommandAsync;
}
private async Task HandleCommandAsync(SocketMessage s)
{
var msg = s as SocketUserMessage;
if(msg == null) return;
var context = new SocketCommandContext(_client, msg);
int argPos = 0;
if (msg.HasCharPrefix(cmdLetter, ref argPos))
{
var result = await _service.ExecuteAsync(context, argPos, null);
if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
{
await context.Channel.SendMessageAsync(result.ErrorReason);
}
}
}
}
}