MessageReactionAdded may not have User in cache
Created by: js6pak
Summary
Seems like DiscordClient user cache may not have reacting user while MESSAGE_REACTION_ADDED
event.
Details
[2020-05-21 00:53:53 +00:00] [DSharpPlus] [Error] An System.AggregateException occurred in MESSAGE_REACTION_ADDED.
System.AggregateException: Exceptions occured within one or more event handlers. Check InnerExceptions for details. (The given key '6973590442598727xx' was not present in the dictionary.) (The given key '6973590442598727xx' was not present in the dictionary.) (The given key '6973590442598727xx' was not present in the dictionary.)
---> System.Collections.Generic.KeyNotFoundException: The given key '6973590442598727xx' was not present in the dictionary.
at System.Collections.Concurrent.ConcurrentDictionary`2.ThrowKeyNotFoundException(Object key)
t System.Collections.Concurrent.ConcurrentDictionary`2.get_Item(TKey key)
at DSharpPlus.Entities.DiscordMember.get_User()
at DSharpPlus.Entities.DiscordMember.get_IsBot()
.NET Core 3.1, D#+ 4.0.0-nightly-00697
Steps to reproduce
- Subscribe to
MessageReactionAdded
event like following (probably other events have same problem)
private async Task Discord_MessageReactionAdded(MessageReactionAddEventArgs e)
{
if (e.User.IsBot)
return;
}
- Add bot to server with hidden offline members (100 members+?), and set your status to
Invisible
- Add reaction to any message without writing any message (or any other action that could add you to user cache)
Notes
This could be resolved by adding fallback Guild#GetUserAsync
in https://github.com/DSharpPlus/DSharpPlus/blob/master/DSharpPlus/Entities/DiscordMember.cs#L151 or just getting User object from event?
Workaround:
this.Discord.MessageReactionAdded += e => e.Client.GetUserAsync(e.User.Id);