title: C# Discord bot log recieved messages
body: <p>I'm trying to set up a discord Bot in c#. the first thing I wanna do is get a message logger. I read through a lot of methods but they are kinda complicated. I think its possible to use an equivalent of python's OnMessageRecieved function. I know that theres the _client.MessageRecieved something but I cant figure out how to use it properly. So, is there any simple way to log recieved messages?</p>
  <p>Heres my code so far:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Reflection;
  using System.Text;
  using System.Threading.Tasks;
  using Discord;
  using Discord.Commands;
  using Discord.WebSocket;
  using Microsoft.Extensions.DependencyInjection;
  
  namespace Enderbot_2._0
  {
      internal class Program
      {
          static void Main(string[] args) =&gt; new Program().RunBotAsync().GetAwaiter().GetResult();
  
          private DiscordSocketClient _client;
          private CommandService _commands;
          private IServiceProvider _services;
  
          public async Task RunBotAsync()
          {
              _client = new DiscordSocketClient();
              _commands = new CommandService();
              _services = new ServiceCollection()
                  .AddSingleton(_client)
                  .AddSingleton(_commands)
                  .BuildServiceProvider();
              _client.Ready += OnReady;
  
              string token = &quot;something&quot;;
  
              await RegisterCommandsAsync();
  
              await _client.LoginAsync(TokenType.Bot, token);
  
              await _client.StartAsync();
  
              await Task.Delay(-1);
          }
  
          private async Task OnReady()
          {
              Console.WriteLine(&quot;Enderbot 2.0 is ready!&quot;);
          }
  
          public async Task RegisterCommandsAsync()
          {
              _client.MessageReceived += HandleCommandAsync;
              await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
          }
  
          private async Task HandleCommandAsync(SocketMessage arg)
          {
              var message = arg as SocketUserMessage;
              var context = new SocketCommandContext(_client, message);
              if (message.Author.IsBot) return;
  
              int argPos = 0;
              if (message.HasStringPrefix(&quot;&gt;&quot;, ref argPos))
              {
                  var result = await _commands.ExecuteAsync(context, argPos, _services);
                  if (!result.IsSuccess) Console.WriteLine(result.ErrorReason);
              }
          }
      }
  }
  
  </code></pre>