Skip to content

Commit

Permalink
[commands] custom default arguments
Browse files Browse the repository at this point in the history
Modeled slightly after Converters, allow specifying Converter-like class
for context-based default parameters. e.g.

```py
class Author(ParamDefault):
  async def default(self, ctx):
    return ctx.author

async def my_command(ctx, user: discord.Member=Author):
  ...
```

Also adds a few common cases (Author, Channel, Guild) for current
author, ...
  • Loading branch information
khazhyk committed May 8, 2019
1 parent 48f9c91 commit 8fc8d08
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ async def _resolve_default(self, ctx, param):
if inspect.isclass(param.default) and issubclass(param.default, defaults.CustomDefault):
instance = param.default()
return await instance.default(ctx=ctx, param=param)
elif isinstance(param.default, converters.CustomDefault):
elif isinstance(param.default, defaults.CustomDefault):
return await param.default.default(ctx=ctx, param=param)
except CommandError as e:
raise e
Expand Down

0 comments on commit 8fc8d08

Please sign in to comment.