Discord.net: DiscordSocketClient.GetUser(ulong id) returns null for normal users

Created on 27 Oct 2020  路  3Comments  路  Source: discord-net/Discord.Net

I have a method to get mentioned Users:

public DiscordSocketClient client;
public static SocketUser FromMention(string mention) {
    Regex regex = new Regex("^<@!{0,1}(\\d+)>$");
    Match match = regex.Match(mention);
    if (!match.Success) {
        return null;
    }

    ulong id = ulong.Parse(match.Groups.Values.ToArray()[1].Value);
    return client.GetUser(id); 
}

which stopped working like a week ago (maybe I just didnt notice it before) because GetUser started to return null for active online users. These users are not invisible, offline or inactive. I also tried this with a testinstance of the bot with just 2 servers and less than 50 users and the problem still occures. Some users are null everytime.

I also tried to use the DownloadUsersAsync functions but it didnt help either.

Most helpful comment

Related to https://github.com/discord-net/Discord.Net/issues/1656 (some temporary solutions are over there already)

This issue is caused by Discord recently disabling "privileged intents" in their gateway. It does not appear Discord.Net has updated the public release to meet the new requirements for accessing the members list from a single guild. The dev release has a fix.
https://support-dev.discord.com/hc/en-us/articles/360056426994

All 3 comments

There is a TypeReader for users... why aren't you using that?

I just tried this right now, and it does successfully get the user. How many guilds is the bot in?

Related to https://github.com/discord-net/Discord.Net/issues/1656 (some temporary solutions are over there already)

This issue is caused by Discord recently disabling "privileged intents" in their gateway. It does not appear Discord.Net has updated the public release to meet the new requirements for accessing the members list from a single guild. The dev release has a fix.
https://support-dev.discord.com/hc/en-us/articles/360056426994

Ok its really easy to fix.
You just have to enable intents for your bot in the discord developer portal.
image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Kwoth picture Kwoth  路  8Comments

nbroza picture nbroza  路  5Comments

MinisBett picture MinisBett  路  3Comments

Poyser1911 picture Poyser1911  路  4Comments

Foxite picture Foxite  路  4Comments