aboutsummaryrefslogtreecommitdiff
path: root/discord
diff options
context:
space:
mode:
Diffstat (limited to 'discord')
-rw-r--r--discord/ext/commands/core.py26
1 files changed, 22 insertions, 4 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py
index 7cd736d4..e9dbd385 100644
--- a/discord/ext/commands/core.py
+++ b/discord/ext/commands/core.py
@@ -24,6 +24,7 @@ DEALINGS IN THE SOFTWARE.
from typing import (
Any,
+ Callable,
Dict,
Literal,
Union,
@@ -69,8 +70,18 @@ __all__ = (
'bot_has_guild_permissions'
)
-def get_signature_parameters(function: types.FunctionType) -> Dict[str, inspect.Parameter]:
- globalns = function.__globals__
+def unwrap_function(function: Callable[..., Any]) -> Callable[..., Any]:
+ partial = functools.partial
+ while True:
+ if hasattr(function, '__wrapped__'):
+ function = function.__wrapped__
+ elif isinstance(function, partial):
+ function = function.func
+ else:
+ return function
+
+
+def get_signature_parameters(function: Callable[..., Any], globalns: Dict[str, Any]) -> Dict[str, inspect.Parameter]:
signature = inspect.signature(function)
params = {}
cache: Dict[str, Any] = {}
@@ -329,8 +340,15 @@ class Command(_BaseCommand):
@callback.setter
def callback(self, function):
self._callback = function
- self.module = function.__module__
- self.params = get_signature_parameters(function)
+ unwrap = unwrap_function(function)
+ self.module = unwrap.__module__
+
+ try:
+ globalns = unwrap.__globals__
+ except AttributeError:
+ globalns = {}
+
+ self.params = get_signature_parameters(function, globalns)
def add_check(self, func):
"""Adds a check to the command.