Discord user is NULL
See original GitHub issueGot some weird issues after the update to the latest lib version. I read user command from chat to proceed with authentication, get the author ID and then try to get SocketGuildUser
using the SocketGuild.GetUser(ID)
but it returns NULL. User is in the guild, transition from command to processing logic is less than a second. The problem is that the issue is floating, sometimes it works just fine.
- I call
await discordGuild.DownloadUsersAsync();
before the processing to make sure the cache is up to date. - I have one guild with strict ID specified
- I have this one guild cached in a variable at startup (can be a problem here?)
- Guild
IsConnected
andHasAllMembers
properties areTrue
. Restart do not solve it.
Please help me to get a clue on what is going on and how i can solve it.
PS: seems like users cache leaves old users after I purge them from discord and call DownloadUsersAsync
, it shows 990 users against 737 in discord. After bot restart it shows correct 737 but the issue still remains.
PS2: When I’ve added extended logging and restarted the bot one more time, it passed the check :E Will wait for another issue. Can’t reproduce with my alt reg.
Issue Analytics
- State:
- Created 3 years ago
- Comments:27 (7 by maintainers)
Top GitHub Comments
Just in case anybody hasn’t sussed this out, the GetUser(id) method only interacts with the client’s cache. If you’re having issues with the cache and need to get someone by ID, use GetUserAsync(id) which directly queries Discord’s REST API.
I found that on the nightly builds, neither
AlwaysDownloadUsers = true
norSocketGuild.DownloadUsersAsync()
work, despite having the GuildMembers and Guild intents enabled. They don’t throw an error, they just get stuck.If I enable the presence intents, AlwaysDownloadUsers works again. I don’t see why presence data should be required to get the members of the server, so I’m putting this down to a bug in the library.
Assuming it is a bug with the library, it needs to be fixed as soon as possible because otherwise verified bots with the guild members intent but without the presence intent aren’t able to fill their user cache.
Edit: I have since discovered that DownloadUsersAsync() doesn’t work in the ready or guild available handlers, but using it in the connected / shardconnected handlers works great! I hope this helps.
Indeed I can confirm, that you need both Intents. Only Server Member Intent does not work. This fixed it for me.