diff options
| author | Rapptz <[email protected]> | 2017-06-01 03:32:18 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2017-06-01 03:32:18 -0400 |
| commit | 5e6491c3fedf2b23e6e1593f473ca4d30d61179c (patch) | |
| tree | a6468c60253f02071be2ba625e0fa816f93b4cf5 | |
| parent | Minor fix in migrating page. (diff) | |
| download | discord.py-5e6491c3fedf2b23e6e1593f473ca4d30d61179c.tar.xz discord.py-5e6491c3fedf2b23e6e1593f473ca4d30d61179c.zip | |
[commands] Allow inline advanced converters via classmethods.
That way you don't need to have, e.g. Foo and FooConverter and can
do it inline via Foo instead.
| -rw-r--r-- | discord/ext/commands/core.py | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 3655deaf..4c541f41 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -204,10 +204,16 @@ class Command: if converter.__module__.startswith('discord.') and not converter.__module__.endswith('converter'): converter = getattr(converters, converter.__name__ + 'Converter') - if inspect.isclass(converter) and issubclass(converter, converters.Converter): - instance = converter() - ret = yield from instance.convert(ctx, argument) - return ret + if inspect.isclass(converter): + if issubclass(converter, converters.Converter): + instance = converter() + ret = yield from instance.convert(ctx, argument) + return ret + else: + method = getattr(converter, 'convert', None) + if method is not None and inspect.ismethod(method): + ret = yield from method(ctx, argument) + return ret elif isinstance(converter, converters.Converter): ret = yield from converter.convert(ctx, argument) return ret |