Skip to content

[Bug]: UserJoin doesn't fire despite correct intents and configuration #3085

@MichaelGlaive

Description

@MichaelGlaive

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

I setup all the intents, and settings on discord, and my code requests ALL the intents (so I can't be missing them). Yet UserJoin doesn't fire when I test joining the user.

Version

3.17.2

Working Version

No response

Logs

info: DiscordDmBot.DiscordBotService[0]
      17:20:28 Gateway     Received Dispatch (GUILD_MEMBER_ADD)
info: DiscordDmBot.DiscordBotService[0]
      17:20:28 Gateway     Unsynced Guild (GUILD_MEMBER_ADD Guild=1354752827683242076).
info: DiscordDmBot.DiscordBotService[0]
      17:20:29 Gateway     Received Dispatch (PRESENCE_UPDATE)
info: DiscordDmBot.DiscordBotService[0]
      17:20:29 Gateway     Unsynced Guild (PRESENCE_UPDATE Guild=1354752827683242076).

Sample

using Discord;
using Discord.WebSocket;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using System;
using System.Threading;
using System.Threading.Tasks;

namespace DiscordDmBot
{
    public class Program
    {
        public static async Task Main(string[] args)
        {
            // Create the service collection and configure it
            var services = new ServiceCollection()
                .AddSingleton(new DiscordSocketClient(new DiscordSocketConfig()
                {
                    LogLevel = LogSeverity.Debug,
                    MessageCacheSize = 10,
                    SuppressUnknownDispatchWarnings = true,
                    GatewayIntents = GatewayIntents.All,
                    AlwaysDownloadUsers = true,
                    LogGatewayIntentWarnings = true,
                }))
                .AddSingleton<DiscordBotService>()
                .AddLogging(builder => builder.AddConsole());

            // Build the service provider
            var serviceProvider = services.BuildServiceProvider();

            // Start the bot
            await serviceProvider.GetRequiredService<DiscordBotService>().StartAsync();

            // Keep the program running
            await Task.Delay(Timeout.Infinite);
        }
    }

    public class DiscordBotService
    {
        private readonly DiscordSocketClient _client;
        private readonly ILogger<DiscordBotService> _logger;
        private readonly string _token = "SECRET TOKEN HERE"; // Replace with your token

        public DiscordBotService(DiscordSocketClient client, ILogger<DiscordBotService> logger)
        {
            _client = client;
            _logger = logger;

            // Subscribe to client events
            _client.Log += LogAsync;
            _client.Ready += ReadyAsync;
            _client.MessageReceived += MessageReceivedAsync;
        }

        public async Task StartAsync()
        {
            await _client.LoginAsync(TokenType.Bot, _token);
            await _client.StartAsync();
        }

        private Task LogAsync(LogMessage log)
        {
            _logger.LogInformation(log.ToString());
            return Task.CompletedTask;
        }

        private Task ReadyAsync()
        {
            _logger.LogInformation("{User} is connected!", _client.CurrentUser);
            _client.UserJoined += UserJoinedAsync;
            _client.UserLeft += UserLeftAsync;
            _client.GuildMemberUpdated += MemberUpdatedAsync;

            return Task.CompletedTask;
        }

        private Task UserLeftAsync(SocketGuild guild, SocketUser user)
        {
            _logger.LogInformation("User {User} LEFT: {Guild}", user.Username, guild.Name);
            return Task.CompletedTask;
        }

        private Task MemberUpdatedAsync(Cacheable<SocketGuildUser, ulong> userCacheable, SocketGuildUser user)
        {
            _logger.LogInformation("Member UPDATED: {User}", user.Username);
            return Task.CompletedTask;
        }

        private async Task MessageReceivedAsync(SocketMessage message)
        {
            // Ignore messages from bots
            if (message.Author.IsBot) return;

            // Only process direct messages
            if (message.Channel is not IDMChannel) return;

            _logger.LogInformation("Received DM from {Username}: {Content}", message.Author.Username, message.Content);

            await message.Channel.SendMessageAsync($"You said: {message.Content}");
        }

        private async Task UserJoinedAsync(SocketGuildUser user)
        {
            var dmChannel = await user.CreateDMChannelAsync();
            await dmChannel.SendMessageAsync("Welcome to the server!, please paste your solaria user id here to get started...");
        }
    }
}

Packages

Discord.Net 3.17.2

Environment

macOS 14.6.1, Apple Silicon.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions