title: Discord.NET: UserJoined Event not being called
body: <p>I'm building a Discord bot using Discord.NET which is supposed to report a user joining, leaving, being kicked and being banned to a mod/admin-only auditing channel, except I can't get the relevant function to trigger when a user joins the guild.</p>
  <p>I removed my message sending code and replaced it with a console output to determine whether or not the problem is the event not triggering or the send message request not working and found the event wasn't being triggered.</p>
  <p>I've enabled all the intents in the Bot management console.
  <a href="https://i.stack.imgur.com/YWFev.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YWFev.jpg" alt="Screenshot of bot management console" /></a></p>
  <p>I've added intents according to the <a href="https://discordnet.dev/guides/v2_v3_guide/v2_to_v3_guide.html" rel="nofollow noreferrer">documentation</a>:</p>
  <pre class="lang-csharp prettyprint-override"><code>var socketConfig = new DiscordSocketConfig
  {
      GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | GatewayIntents.GuildBans
  };
  
  _client = new DiscordSocketClient(socketConfig);
  </code></pre>
  <p>I've then registered the event: (Note: <code>_client = client;</code> is used before this)</p>
  <pre class="lang-csharp prettyprint-override"><code>client.UserJoined += UserJoined;
  </code></pre>
  <p>And finally written the function to be triggered:</p>
  <pre class="lang-csharp prettyprint-override"><code>public Task UserJoined(SocketGuildUser user)
  {
      Console.Write(&quot;User &quot;);
      Console.Write(user.Username);
      Console.WriteLine(&quot; joined.&quot;);
  
      return Task.CompletedTask;
  }
  </code></pre>
  <p>Is there anything I've not done or done wrong here? I've spent about two days on this with absolutely no idea what the problem is, everything seems to point to me doing everything right yet I'm unable to receive this event from Discord.</p>
  <p>Every change I've made I've additionally tried removing and re-adding the bot to my test server. I also don't receive any kind of message similar to <code>[12/8/2018 10:01:30 PM at Gateway] Received Dispatch (GUILD_MEMBER_ADD)</code> as mentioned in <a href="https://stackoverflow.com/questions/53698884/userjoined-event-handler-not-being-called">this</a> post.</p>
  <p>I've included my full Program.cs below:</p>
  <pre class="lang-csharp prettyprint-override"><code>using System;
  using Discord;
  using Discord.Net;
  using Discord.Commands;
  using Discord.WebSocket;
  using System.Threading.Tasks;
  using Microsoft.Extensions.Configuration;
  using Microsoft.Extensions.Configuration.Json;
  using Microsoft.Extensions.DependencyInjection;
  using BanBot2.Bot.Services;
  
  namespace BanBot2.Bot
  {
      class Program
      {
          // setup our fields we assign later
          private readonly IConfiguration _iconfig;
          private DiscordSocketClient _client;
  
          static void Main(string[] args) =&gt; new Program().MainAsync().GetAwaiter().GetResult();
  
          public Program()
          {
              var socketConfig = new DiscordSocketConfig
              {
                  GatewayIntents = GatewayIntents.AllUnprivileged | GatewayIntents.GuildMembers | GatewayIntents.GuildBans
              };
  
              _client = new DiscordSocketClient(socketConfig);
              
              // create the configuration
              var _builder = new ConfigurationBuilder()
                  .SetBasePath(AppContext.BaseDirectory)
                  .AddJsonFile(path: &quot;application.json&quot;);  
  
              // build the configuration and assign to _config          
              _iconfig = _builder.Build();
          }
  
          public async Task MainAsync()
          {
              // call ConfigureServices to create the ServiceCollection/Provider for passing around the services
              using (var services = ConfigureServices())
              {
                  // get the client and assign to client 
                  // you get the services via GetRequiredService&lt;T&gt;
                  var client = services.GetRequiredService&lt;DiscordSocketClient&gt;();
                  _client = client;
  
                  // setup logging and the ready event
                  client.Log += LogAsync;
                  client.Ready += ReadyAsync;
                  client.UserJoined += UserJoined;
                  services.GetRequiredService&lt;CommandService&gt;().Log += LogAsync;
  
                  // this is where we get the Token value from the configuration file, and start the bot
                  await client.LoginAsync(TokenType.Bot, _iconfig[&quot;Token&quot;]);
                  await client.StartAsync();
  
                  // we get the CommandHandler class here and call the InitializeAsync method to start things up for the CommandHandler service
                  await services.GetRequiredService&lt;CommandHandler&gt;().InitializeAsync();
  
                  await Task.Delay(-1);
              }
          }
  
          public Task UserJoined(SocketGuildUser user)
          {
              Console.Write(&quot;User @&quot;);
              Console.Write(user.Username);
              Console.WriteLine(&quot; joined.&quot;);
  
              return Task.CompletedTask;
          }
  
          private Task LogAsync(LogMessage log)
          {
              Console.WriteLine(log.ToString());
              return Task.CompletedTask;
          }
  
          private Task ReadyAsync()
          {
              Console.WriteLine($&quot;Connected as -&gt; [{_client.CurrentUser}] :)&quot;);
              return Task.CompletedTask;
          }
  
          // this method handles the ServiceCollection creation/configuration and builds out the service provider we can call on later
          private ServiceProvider ConfigureServices()
          {
              // this returns a ServiceProvider that is used later to call for those services
              // we can add types we have access to here, hence adding the new using statement:
              // using BanBot2.Bot.Services;
              // the config we build is also added, which comes in handy for setting the command prefix!
              return new ServiceCollection()
                  .AddSingleton(_iconfig)
                  .AddSingleton&lt;DiscordSocketClient&gt;()
                  .AddSingleton&lt;CommandService&gt;()
                  .AddSingleton&lt;CommandHandler&gt;()
                  .BuildServiceProvider();
          }
      }
  }
  </code></pre>