diff options
| author | Rapptz <[email protected]> | 2020-02-02 19:10:22 -0500 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-02-02 19:11:50 -0500 |
| commit | bb1c1e9fa3b80b55166817e1e7f828d9a76c0ff1 (patch) | |
| tree | 241165400f2407b3b3721433e805f20ce7ae9961 | |
| parent | Guard against the member data not being available in VOICE_STATE_UPDATE (diff) | |
| download | discord.py-bb1c1e9fa3b80b55166817e1e7f828d9a76c0ff1.tar.xz discord.py-bb1c1e9fa3b80b55166817e1e7f828d9a76c0ff1.zip | |
[commands] Raise when passing invalid permission keys in their checks
| -rw-r--r-- | discord/ext/commands/core.py | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index ddcdfa26..e1e12cc5 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 |