From af51438508648087eae5353af3536e7c7e0d373f Mon Sep 17 00:00:00 2001 From: Paulo Date: Mon, 18 Feb 2019 23:03:08 -0300 Subject: [PATCH] Fix NullReferenceException at MESSAGE_CREATE 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 --- src/Discord.Net.WebSocket/DiscordSocketClient.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index 196aedf47..29e1b421a 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -1173,9 +1173,13 @@ namespace Discord.WebSocket { 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);