-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandHandler.cs
36 lines (30 loc) · 1.08 KB
/
CommandHandler.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
using System.Reflection;
using Discord.Commands;
using Discord.WebSocket;
namespace Portal;
public class CommandHandler(DiscordSocketClient discordSocketClient,
CommandService commandService, IServiceProvider serviceProvider)
{
public async Task InstallCommandsAsync()
{
await commandService.AddModulesAsync(assembly: Assembly.GetEntryAssembly(), serviceProvider);
discordSocketClient.MessageReceived += HandleCommandAsync;
}
private async Task HandleCommandAsync(SocketMessage messageParam)
{
var message = messageParam as SocketUserMessage;
if (message == null) return;
int argPos = 0;
if (!message.HasCharPrefix('!', ref argPos) ||
message.HasMentionPrefix(discordSocketClient.CurrentUser, ref argPos) ||
message.Author.IsBot)
{
return;
}
var context = new SocketCommandContext(discordSocketClient, message);
await commandService.ExecuteAsync(
context: context,
argPos: argPos,
services: serviceProvider);
}
}