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:
@@ -57,13 +57,11 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
if (ChannelPermission.HasValue)
|
if (ChannelPermission.HasValue)
|
||||||
{
|
{
|
||||||
var guildChannel = context.Channel as IGuildChannel;
|
|
||||||
|
|
||||||
ChannelPermissions perms;
|
ChannelPermissions perms;
|
||||||
if (guildChannel != null)
|
if (context.Channel is IGuildChannel guildChannel)
|
||||||
perms = guildUser.GetPermissions(guildChannel);
|
perms = guildUser.GetPermissions(guildChannel);
|
||||||
else
|
else
|
||||||
perms = ChannelPermissions.All(guildChannel);
|
perms = ChannelPermissions.All(context.Channel);
|
||||||
|
|
||||||
if (!perms.Has(ChannelPermission.Value))
|
if (!perms.Has(ChannelPermission.Value))
|
||||||
return PreconditionResult.FromError($"Bot requires channel permission {ChannelPermission.Value}");
|
return PreconditionResult.FromError($"Bot requires channel permission {ChannelPermission.Value}");
|
||||||
|
|||||||
@@ -56,13 +56,11 @@ namespace Discord.Commands
|
|||||||
|
|
||||||
if (ChannelPermission.HasValue)
|
if (ChannelPermission.HasValue)
|
||||||
{
|
{
|
||||||
var guildChannel = context.Channel as IGuildChannel;
|
|
||||||
|
|
||||||
ChannelPermissions perms;
|
ChannelPermissions perms;
|
||||||
if (guildChannel != null)
|
if (context.Channel is IGuildChannel guildChannel)
|
||||||
perms = guildUser.GetPermissions(guildChannel);
|
perms = guildUser.GetPermissions(guildChannel);
|
||||||
else
|
else
|
||||||
perms = ChannelPermissions.All(guildChannel);
|
perms = ChannelPermissions.All(context.Channel);
|
||||||
|
|
||||||
if (!perms.Has(ChannelPermission.Value))
|
if (!perms.Has(ChannelPermission.Value))
|
||||||
return Task.FromResult(PreconditionResult.FromError($"User requires channel permission {ChannelPermission.Value}"));
|
return Task.FromResult(PreconditionResult.FromError($"User requires channel permission {ChannelPermission.Value}"));
|
||||||
|
|||||||
Reference in New Issue
Block a user