[Bug]: GetUser for specific user returns null
Draco18s opened this issue · 2 comments
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 have the code (sample below). When a message comes in on a guild text channel that @-mentions a user who has been converted to non-discriminator username, this code fails to fetch that user, returning null.
But it's just this ONE user as far as I can tell. In my discord client I am able to see, mention, and so on without any issue, but the bot (which gets @-mentions as pure IDs and has to convert those to usernames/display names) outright fails to fetch the user's info.
I am willing to supply the offending user ID (privately) if required.
Version
3.10.0
Working Version
No response
Logs
n/a as the crash occurs in my code
Sample
public static SocketUser GetUser(ulong id, ulong channelID)
{
// if we can just get the user, get the user
SocketUser s = Instance._client.GetUser(id);
if (s != null) return s;
// if this is a channel and the user is in the user list, get that user
SocketChannel chan = Instance._client.GetChannel(channelID);
IReadOnlyCollection<SocketUser> a = chan.Users;
foreach (SocketUser? o in a)
{
if (o.Id == id)
return o;
}
// if both of those failed, get the current guild and get the user from there
if (chan is SocketTextChannel g)
{
s = g.Guild.GetUser(id);
if (s != null) return s;
}
return null; //well f-ck
}
Packages
System.Data.SQLite v1.0.117
Word2vec.Tools v2.1.0
(Both used in other sections of the bot for storing and retrieving "memories")
Try using the IGuild.GetUserAsync()
method instead of GetUser
GetUser
only fetches users from client's cache, while the GetUserAsync
does a API request if it can't find the user in cache.
Doh. Of course 🤦♂️