[commands] Force the predicate attribute in checks to be a coroutine
This commit is contained in:
parent
82797b0e60
commit
e5870903f5
@ -1321,12 +1321,13 @@ def check(predicate):
|
||||
def extended_check(ctx):
|
||||
if ctx.guild is None:
|
||||
return False
|
||||
return ctx.guild.owner_id == ctx.author.id or original(ctx)
|
||||
return ctx.guild.owner_id == ctx.author.id or await original(ctx)
|
||||
return commands.check(extended_check)
|
||||
|
||||
.. note::
|
||||
|
||||
These functions can either be regular functions or coroutines.
|
||||
The function returned by ``predicate`` is **always** a coroutine,
|
||||
even if the original function was not a coroutine.
|
||||
|
||||
.. versionchanged:: 1.3.0
|
||||
The ``predicate`` attribute was added.
|
||||
@ -1377,7 +1378,14 @@ def check(predicate):
|
||||
|
||||
return func
|
||||
|
||||
if inspect.iscoroutinefunction(predicate):
|
||||
decorator.predicate = predicate
|
||||
else:
|
||||
@functools.wraps(predicate)
|
||||
async def wrapper(ctx):
|
||||
return predicate(ctx)
|
||||
decorator.predicate = wrapper
|
||||
|
||||
return decorator
|
||||
|
||||
def check_any(*checks):
|
||||
@ -1435,10 +1443,9 @@ def check_any(*checks):
|
||||
|
||||
async def predicate(ctx):
|
||||
errors = []
|
||||
maybe = discord.utils.maybe_coroutine
|
||||
for func in unwrapped:
|
||||
try:
|
||||
value = await maybe(func, ctx)
|
||||
value = await func(ctx)
|
||||
except CheckFailure as e:
|
||||
errors.append(e)
|
||||
else:
|
||||
@ -1465,10 +1472,6 @@ def has_role(item):
|
||||
is missing a role, or :exc:`.NoPrivateMessage` if it is used in a private message.
|
||||
Both inherit from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionchanged:: 1.1.0
|
||||
|
||||
Raise :exc:`.MissingRole` or :exc:`.NoPrivateMessage`
|
||||
@ -1505,10 +1508,6 @@ def has_any_role(*items):
|
||||
is missing all roles, or :exc:`.NoPrivateMessage` if it is used in a private message.
|
||||
Both inherit from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionchanged:: 1.1.0
|
||||
|
||||
Raise :exc:`.MissingAnyRole` or :exc:`.NoPrivateMessage`
|
||||
@ -1548,10 +1547,6 @@ def bot_has_role(item):
|
||||
is missing the role, or :exc:`.NoPrivateMessage` if it is used in a private message.
|
||||
Both inherit from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionchanged:: 1.1.0
|
||||
|
||||
Raise :exc:`.BotMissingRole` or :exc:`.NoPrivateMessage`
|
||||
@ -1581,10 +1576,6 @@ def bot_has_any_role(*items):
|
||||
is missing all roles, or :exc:`.NoPrivateMessage` if it is used in a private message.
|
||||
Both inherit from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionchanged:: 1.1.0
|
||||
|
||||
Raise :exc:`.BotMissingAnyRole` or :exc:`.NoPrivateMessage`
|
||||
@ -1615,10 +1606,6 @@ def has_permissions(**perms):
|
||||
This check raises a special exception, :exc:`.MissingPermissions`
|
||||
that is inherited from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
Parameters
|
||||
------------
|
||||
perms
|
||||
@ -1654,10 +1641,6 @@ def bot_has_permissions(**perms):
|
||||
|
||||
This check raises a special exception, :exc:`.BotMissingPermissions`
|
||||
that is inherited from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
"""
|
||||
def predicate(ctx):
|
||||
guild = ctx.guild
|
||||
@ -1680,10 +1663,6 @@ def has_guild_permissions(**perms):
|
||||
If this check is called in a DM context, it will raise an
|
||||
exception, :exc:`.NoPrivateMessage`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionadded:: 1.3.0
|
||||
"""
|
||||
def predicate(ctx):
|
||||
@ -1704,10 +1683,6 @@ def bot_has_guild_permissions(**perms):
|
||||
"""Similar to :func:`.has_guild_permissions`, but checks the bot
|
||||
members guild permissions.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionadded:: 1.3.0
|
||||
"""
|
||||
def predicate(ctx):
|
||||
@ -1732,10 +1707,6 @@ def dm_only():
|
||||
This check raises a special exception, :exc:`.PrivateMessageOnly`
|
||||
that is inherited from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionadded:: 1.1.0
|
||||
"""
|
||||
|
||||
@ -1753,10 +1724,6 @@ def guild_only():
|
||||
|
||||
This check raises a special exception, :exc:`.NoPrivateMessage`
|
||||
that is inherited from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
"""
|
||||
|
||||
def predicate(ctx):
|
||||
@ -1774,10 +1741,6 @@ def is_owner():
|
||||
|
||||
This check raises a special exception, :exc:`.NotOwner` that is derived
|
||||
from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function **is** a coroutine.
|
||||
"""
|
||||
|
||||
async def predicate(ctx):
|
||||
@ -1793,10 +1756,6 @@ def is_nsfw():
|
||||
This check raises a special exception, :exc:`.NSFWChannelRequired`
|
||||
that is derived from :exc:`.CheckFailure`.
|
||||
|
||||
.. note::
|
||||
|
||||
The ``predicate`` attribute for this function is **not** a coroutine.
|
||||
|
||||
.. versionchanged:: 1.1.0
|
||||
|
||||
Raise :exc:`.NSFWChannelRequired` instead of generic :exc:`.CheckFailure`.
|
||||
|
Loading…
x
Reference in New Issue
Block a user