Browse Source

[commands] Raise when passing invalid permission keys in their checks

pull/2554/head
Rapptz 5 years ago
parent
commit
bb1c1e9fa3
  1. 28
      discord/ext/commands/core.py

28
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

Loading…
Cancel
Save