Skip to content

Commit

Permalink
fix: Fix NullReferenceException at MESSAGE_CREATE (#1268)
Browse files Browse the repository at this point in the history
After talking at the Discord.Net channel, @Quahu stated the `member` prop doesn't contain the `user` in this payload (and it's described as being a partial at https://discordapp.com/developers/docs/resources/channel#message-object).

I completed it using the `author` prop, that I believe it's the cleanest way of dealing with it (without changing the GuildMember class or the AddOrUpdateUser method).

Solves #1267
  • Loading branch information
SubZero0 authored and foxbot committed Mar 16, 2019
1 parent b80f0e8 commit 377622b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Discord.Net.WebSocket/DiscordSocketClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,9 +1173,13 @@ private async Task ProcessMessageAsync(GatewayOpCode opCode, int? seq, string ty
{
if (guild != null)
{
author = data.Member.IsSpecified // member isn't always included, but use it when we can
? guild.AddOrUpdateUser(data.Member.Value)
: guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data
if (data.Member.IsSpecified) // member isn't always included, but use it when we can
{
data.Member.Value.User = data.Author.Value;
author = guild.AddOrUpdateUser(data.Member.Value);
}
else
author = guild.AddOrUpdateUser(data.Author.Value); // user has no guild-specific data
}
else if (channel is SocketGroupChannel)
author = (channel as SocketGroupChannel).GetOrAddUser(data.Author.Value);
Expand Down

0 comments on commit 377622b

Please sign in to comment.