Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.05 KB | None | 0 0
  1. class CommandHandler
  2.     {
  3.         DiscordSocketClient _client;
  4.         CommandService _service;
  5.  
  6.         public async Task InitializeAsync(DiscordSocketClient client)
  7.         {
  8.             _client = client;
  9.             await _service.AddModulesAsync(Assembly.GetEntryAssembly(), null);
  10.             _client.MessageReceived += HandleCommandAsync;
  11.         }
  12.  
  13.         private async Task HandleCommandAsync(SocketMessage s)
  14.         {
  15.             var msg = s as SocketUserMessage;
  16.             if (msg == null) return;
  17.             var context = new SocketCommandContext(_client, msg);
  18.             int argPos = 0;
  19.             if (msg.HasStringPrefix(Config.bot.cmdPrefix, ref argPos) || msg.HasMentionPrefix(_client.CurrentUser, ref argPos))
  20.             {
  21.                 var result = await _service.ExecuteAsync(context, argPos, null);
  22.                 if (!result.IsSuccess && result.Error != CommandError.UnknownCommand)
  23.                 {
  24.                     Console.WriteLine(result.ErrorReason);
  25.                 }
  26.             }
  27.         }
  28.     }
  29.    
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement