未调用 UserJoined 事件

UserJoined event is not being called

我正在为 Discord 开发一个机器人,直到最近机器人停止调用事件 UserJoined 和 UserLeft 时,它一直运行良好。 我已将断点放在 UserJoined 的方法中,但不再调用它。该程序不会去那里。也没有例外,什么也没有发生。 我一直在使用 Discord.NET 的 2.1.1 版本,现在尝试解决我尝试将项目升级到 2.2.0 的问题。该方法仍未调用。

有什么问题吗?

  class Program
{
    static void Main(string[] args) => new
        Program().RunBotAsync().GetAwaiter().GetResult();

    private DiscordSocketClient _client;
    private CommandService _commands;
    private IServiceProvider _services;
    private ISWAIService _shAiService;

    
    public async Task RunBotAsync()
    {
        var config = new DiscordSocketConfig { MessageCacheSize = 100 };
        _client = new DiscordSocketClient(config);
        _commands = new CommandService();
        _shAiService = new SWAIService(); 

        _services = new ServiceCollection()
            .AddSingleton(_client)
            .AddSingleton(_commands)
            .BuildServiceProvider();


        _client.Log += _client_Log;

        await RegisterCommandsAsync();

        await _client.LoginAsync(TokenType.Bot, StaticSettingsService.GetTOKEN());



        await _client.StartAsync();

       

        await Task.Delay(-1);
    }

    private async Task RegisterCommandsAsync()
    {
        _client.MessageReceived += HandleCommandAsync;
        _client.UserJoined += HandleUserJoinAsync;
        _client.UserLeft += HandleUserLeftAsync;
        _client.MessageDeleted += HandleMsgDeletedAsync;
        await _commands.AddModulesAsync(Assembly.GetEntryAssembly(), _services);
    }
private async Task HandleUserJoinAsync(SocketGuildUser arg)
    {
        var newUserRoleId = StaticSettingsService.GetNewUserRoleId();
        var newUserRole = arg.Guild.GetRole((ulong)newUserRoleId);
        if(newUserRole != null)
        {
            await arg.AddRoleAsync(newUserRole);
        }

        var modsChannel = _client.GetChannel(StaticSettingsService.GetModsSpamChannelId()) as SocketTextChannel;
        await modsChannel.SendMessageAsync("User: username: " + arg.Username + " joined.");
    }    

 }

MessageRecieved 和 MessageDeleted 工作正常。

10 月底,Discord 强制执行 Privileged Intents, one of their previously announced changes for Bots. TO enable them you'd need to visit the Discord Developer Portal,select 您的机器人,单击“机器人”选项卡并导航至“特权意图”部分以启用意图。

看到这个 这是缺少意图的另一个副作用。