Fix null channel being passed in RequirePermission preconditions (#886)

* Fix null channel being passed in RequirePermission preconditions

* c#7 pattern matching
This commit is contained in:
Christopher F
2017-11-21 16:33:46 -05:00
committed by GitHub
parent b4bf046ad4
commit e5dfb6c3e5
2 changed files with 4 additions and 8 deletions

View File

@@ -57,13 +57,11 @@ namespace Discord.Commands
if (ChannelPermission.HasValue)
{
var guildChannel = context.Channel as IGuildChannel;
ChannelPermissions perms;
if (guildChannel != null)
if (context.Channel is IGuildChannel guildChannel)
perms = guildUser.GetPermissions(guildChannel);
else
perms = ChannelPermissions.All(guildChannel);
perms = ChannelPermissions.All(context.Channel);
if (!perms.Has(ChannelPermission.Value))
return PreconditionResult.FromError($"Bot requires channel permission {ChannelPermission.Value}");

View File

@@ -56,13 +56,11 @@ namespace Discord.Commands
if (ChannelPermission.HasValue)
{
var guildChannel = context.Channel as IGuildChannel;
ChannelPermissions perms;
if (guildChannel != null)
if (context.Channel is IGuildChannel guildChannel)
perms = guildUser.GetPermissions(guildChannel);
else
perms = ChannelPermissions.All(guildChannel);
perms = ChannelPermissions.All(context.Channel);
if (!perms.Has(ChannelPermission.Value))
return Task.FromResult(PreconditionResult.FromError($"User requires channel permission {ChannelPermission.Value}"));