aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReinaSakuraba <[email protected]>2017-08-30 18:17:02 -0700
committerRapptz <[email protected]>2017-08-30 23:20:59 -0400
commit10696a275bfd319b55bb7d2ae58e4de8242e2db6 (patch)
treec91df7d07f262f72535eb56e3edffac777b19f17
parent[commands] Add MissingPermissions and BotMissingPermissions (diff)
downloaddiscord.py-10696a275bfd319b55bb7d2ae58e4de8242e2db6.tar.xz
discord.py-10696a275bfd319b55bb7d2ae58e4de8242e2db6.zip
[commands] Have (bot_)has_permissions provide better failure responses
-rw-r--r--discord/ext/commands/core.py23
1 files changed, 21 insertions, 2 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 0f75d36a..070e7e3b 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -1116,6 +1116,9 @@ def has_permissions(**perms):
The permissions passed in must be exactly like the properties shown under
:class:`.discord.Permissions`.
+ This check raises a special exception, :exc:`.MissingPermissions`
+ that is derived from :exc:`.CheckFailure`.
+
Parameters
------------
perms
@@ -1135,7 +1138,13 @@ def has_permissions(**perms):
def predicate(ctx):
ch = ctx.channel
permissions = ch.permissions_for(ctx.author)
- return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
+
+ missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value]
+
+ if not missing:
+ return True
+
+ raise MissingPermissions(missing)
return check(predicate)
@@ -1169,12 +1178,22 @@ def bot_has_any_role(*names):
def bot_has_permissions(**perms):
"""Similar to :func:`.has_permissions` except checks if the bot itself has
the permissions listed.
+
+ This check raises a special exception, :exc:`.BotMissingPermissions`
+ that is derived from :exc:`.CheckFailure`.
"""
def predicate(ctx):
guild = ctx.guild
me = guild.me if guild is not None else ctx.bot.user
permissions = ctx.channel.permissions_for(me)
- return all(getattr(permissions, perm, None) == value for perm, value in perms.items())
+
+ missing = [perm for perm, value in perms.items() if getattr(permissions, perm, None) != value]
+
+ if not missing:
+ return True
+
+ raise BotMissingPermissions(missing)
+
return check(predicate)
def guild_only():