Add null checks to DiscordSocketClient's RemoveXXX functions

This commit is contained in:
RogueException
2016-08-25 05:56:01 -03:00
parent 774b54de72
commit c0db4bbfa3

View File

@@ -359,10 +359,13 @@ namespace Discord.WebSocket
internal SocketGuild RemoveGuild(ulong id)
{
var guild = DataStore.RemoveGuild(id);
foreach (var channel in guild.Channels)
guild.RemoveChannel(channel.Id);
foreach (var user in guild.Members)
guild.RemoveUser(user.Id);
if (guild != null)
{
foreach (var channel in guild.Channels)
guild.RemoveChannel(channel.Id);
foreach (var user in guild.Members)
guild.RemoveUser(user.Id);
}
return guild;
}
@@ -401,8 +404,11 @@ namespace Discord.WebSocket
internal ISocketChannel RemovePrivateChannel(ulong id)
{
var channel = DataStore.RemoveChannel(id) as ISocketPrivateChannel;
foreach (var recipient in channel.Recipients)
recipient.User.RemoveRef(this);
if (channel != null)
{
foreach (var recipient in channel.Recipients)
recipient.User.RemoveRef(this);
}
return channel;
}