aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--discord/ext/commands/core.py28
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