Skip to content

Commit

Permalink
fix(ext.bridge/commands): default arguments with Option don't work (#…
Browse files Browse the repository at this point in the history
…2256)

* fix(ext.commands): command parsing bug

#2089

* changelog: changelog

* style(pre-commit): auto fixes from pre-commit.com hooks

* Apple code suggestion

Co-authored-by: Dorukyum <[email protected]>
Signed-off-by: Middledot <[email protected]>

---------

Signed-off-by: Middledot <[email protected]>
Signed-off-by: Dorukyum <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Dorukyum <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2023
1 parent 99725dd commit a7f4adb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,8 @@ These changes are available on the `master` branch, but have not yet been releas
([#2196](https://github.com/Pycord-Development/pycord/pull/2196))
- Fixed `AttributeError` when running permission checks without the `bot` scope.
([#2113](https://github.com/Pycord-Development/pycord/issues/2113))
- Fixed `Option` not working on bridge commands because `ext.commands.Command` doesn't
recognize them. ([#2256](https://github.com/Pycord-Development/pycord/pull/2256))

## [2.4.1] - 2023-03-20

Expand Down
11 changes: 9 additions & 2 deletions discord/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

from ...commands import (
ApplicationCommand,
Option,
_BaseCommand,
message_command,
slash_command,
Expand Down Expand Up @@ -562,7 +563,13 @@ async def dispatch_error(self, ctx: Context, error: Exception) -> None:
ctx.bot.dispatch("command_error", ctx, error)

async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
required = param.default is param.empty
if isinstance(param.annotation, Option):
default = param.annotation.default
required = param.annotation.required or default is None
else:
default = param.default
required = default is param.empty

converter = get_converter(param)
consume_rest_is_special = (
param.kind == param.KEYWORD_ONLY and not self.rest_is_raw
Expand Down Expand Up @@ -599,7 +606,7 @@ async def transform(self, ctx: Context, param: inspect.Parameter) -> Any:
):
return await converter._construct_default(ctx)
raise MissingRequiredArgument(param)
return param.default
return default

previous = view.index
if consume_rest_is_special:
Expand Down

0 comments on commit a7f4adb

Please sign in to comment.