[commands] Have (bot_)has_permissions provide better failure responses
This commit is contained in:
parent
8646bddc90
commit
10696a275b
@ -1116,6 +1116,9 @@ def has_permissions(**perms):
|
|||||||
The permissions passed in must be exactly like the properties shown under
|
The permissions passed in must be exactly like the properties shown under
|
||||||
:class:`.discord.Permissions`.
|
:class:`.discord.Permissions`.
|
||||||
|
|
||||||
|
This check raises a special exception, :exc:`.MissingPermissions`
|
||||||
|
that is derived from :exc:`.CheckFailure`.
|
||||||
|
|
||||||
Parameters
|
Parameters
|
||||||
------------
|
------------
|
||||||
perms
|
perms
|
||||||
@ -1135,7 +1138,13 @@ def has_permissions(**perms):
|
|||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
ch = ctx.channel
|
ch = ctx.channel
|
||||||
permissions = ch.permissions_for(ctx.author)
|
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)
|
return check(predicate)
|
||||||
|
|
||||||
@ -1169,12 +1178,22 @@ def bot_has_any_role(*names):
|
|||||||
def bot_has_permissions(**perms):
|
def bot_has_permissions(**perms):
|
||||||
"""Similar to :func:`.has_permissions` except checks if the bot itself has
|
"""Similar to :func:`.has_permissions` except checks if the bot itself has
|
||||||
the permissions listed.
|
the permissions listed.
|
||||||
|
|
||||||
|
This check raises a special exception, :exc:`.BotMissingPermissions`
|
||||||
|
that is derived from :exc:`.CheckFailure`.
|
||||||
"""
|
"""
|
||||||
def predicate(ctx):
|
def predicate(ctx):
|
||||||
guild = ctx.guild
|
guild = ctx.guild
|
||||||
me = guild.me if guild is not None else ctx.bot.user
|
me = guild.me if guild is not None else ctx.bot.user
|
||||||
permissions = ctx.channel.permissions_for(me)
|
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)
|
return check(predicate)
|
||||||
|
|
||||||
def guild_only():
|
def guild_only():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user