From bb1c1e9fa3b80b55166817e1e7f828d9a76c0ff1 Mon Sep 17 00:00:00 2001 From: Rapptz Date: Sun, 2 Feb 2020 19:10:22 -0500 Subject: [PATCH] [commands] Raise when passing invalid permission keys in their checks --- discord/ext/commands/core.py | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index ddcdfa262..e1e12cc5b 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -1657,11 +1657,16 @@ def has_permissions(**perms): await ctx.send('You can manage messages.') """ + + invalid = set(perms) - set(discord.Permissions.VALID_FLAGS) + if invalid: + raise TypeError('Invalid permission(s): %s' % (', '.join(invalid))) + def predicate(ctx): ch = ctx.channel permissions = ch.permissions_for(ctx.author) - missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value] + missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value] if not missing: return True @@ -1677,12 +1682,17 @@ def bot_has_permissions(**perms): This check raises a special exception, :exc:`.BotMissingPermissions` that is inherited from :exc:`.CheckFailure`. """ + + invalid = set(perms) - set(discord.Permissions.VALID_FLAGS) + if invalid: + raise TypeError('Invalid permission(s): %s' % (', '.join(invalid))) + def predicate(ctx): guild = ctx.guild me = guild.me if guild is not None else ctx.bot.user permissions = ctx.channel.permissions_for(me) - missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value] + missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value] if not missing: return True @@ -1700,12 +1710,17 @@ def has_guild_permissions(**perms): .. versionadded:: 1.3 """ + + invalid = set(perms) - set(discord.Permissions.VALID_FLAGS) + if invalid: + raise TypeError('Invalid permission(s): %s' % (', '.join(invalid))) + def predicate(ctx): if not ctx.guild: raise NoPrivateMessage permissions = ctx.author.guild_permissions - missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value] + missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value] if not missing: return True @@ -1720,12 +1735,17 @@ def bot_has_guild_permissions(**perms): .. versionadded:: 1.3 """ + + invalid = set(perms) - set(discord.Permissions.VALID_FLAGS) + if invalid: + raise TypeError('Invalid permission(s): %s' % (', '.join(invalid))) + def predicate(ctx): if not ctx.guild: raise NoPrivateMessage permissions = ctx.me.guild_permissions - missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value] + missing = [perm for perm, value in perms.items() if getattr(permissions, perm) != value] if not missing: return True