Advertisement
Dojnaz

CommandHandler.cs

Apr 29th, 2019
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using Discord.Commands;
  2. using Discord.WebSocket;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Reflection;
  8. using System.Threading.Tasks;
  9. using System.Web;
  10.  
  11. namespace ZanoxDiscordBot2
  12. {
  13.     public class CommandHandler
  14.     {
  15.         DiscordSocketClient _client;
  16.         CommandService _service;
  17.  
  18.         public async Task InitializeAsync(DiscordSocketClient client)
  19.         {
  20.             _client = client;
  21.             _service = new CommandService();
  22.             await _service.AddModulesAsync(Assembly.GetEntryAssembly(), null);
  23.             _client.MessageReceived += HandleCommandAsync;
  24.         }
  25.  
  26.         private async Task HandleCommandAsync(SocketMessage s)
  27.         {
  28.             var msg = s as SocketUserMessage;
  29.  
  30.             bool getInvites = false;
  31.             if (getInvites)
  32.             {
  33.                 var invites = await (msg.Author as SocketGuildUser).Guild.GetInvitesAsync();
  34.  
  35.                 string invite = invites.Select(x => x.Url).FirstOrDefault();
  36.             }
  37.  
  38.             if (msg == null) return;
  39.             var context = new SocketCommandContext(_client, msg);
  40.             if (context.User.IsBot) return;
  41.  
  42.             int argPos = 0;
  43.  
  44.             if (msg.HasStringPrefix("", ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
  45.             {
  46.                 Task.Run(() => _service.ExecuteAsync(context, argPos, null));
  47.             }
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement