From 33193b249f934a5ab5076f11036035bd12a34193 Mon Sep 17 00:00:00 2001 From: Middledot Date: Sun, 5 Nov 2023 21:49:03 -0500 Subject: [PATCH 1/4] fix(ext.commands): command parsing bug #2089 --- discord/ext/commands/core.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index d3ce2e07db..6d7f198189 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -49,6 +49,7 @@ message_command, slash_command, user_command, + Option ) from ...enums import ChannelType from ...errors import * @@ -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): + required = param.annotation.required or param.annotation.default is None + default = param.annotation.default + else: + required = (param.default is param.empty) + default = param.default + converter = get_converter(param) consume_rest_is_special = ( param.kind == param.KEYWORD_ONLY and not self.rest_is_raw @@ -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: From 8a696c928db093ac5fb1e122f94f7ca340166d64 Mon Sep 17 00:00:00 2001 From: Middledot Date: Sun, 5 Nov 2023 21:59:52 -0500 Subject: [PATCH 2/4] changelog: changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41f9e96c11..4dd6e0c862 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -180,6 +180,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2192](https://github.com/Pycord-Development/pycord/pull/2192)) - Fixed `DMChannel.recipient` being `None` and consequently `User.dm_channel` also being `None`. ([#2219](https://github.com/Pycord-Development/pycord/pull/2219)) +- 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 From cd7344780bc67d9ed566141a5a37694641ed3762 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 Nov 2023 03:00:31 +0000 Subject: [PATCH 3/4] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/ext/commands/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index 6d7f198189..cd1b274004 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -45,11 +45,11 @@ from ...commands import ( ApplicationCommand, + Option, _BaseCommand, message_command, slash_command, user_command, - Option ) from ...enums import ChannelType from ...errors import * @@ -567,7 +567,7 @@ async def transform(self, ctx: Context, param: inspect.Parameter) -> Any: required = param.annotation.required or param.annotation.default is None default = param.annotation.default else: - required = (param.default is param.empty) + required = param.default is param.empty default = param.default converter = get_converter(param) From dfb2bf18fa7859c14852a6938c5c5bad495f0394 Mon Sep 17 00:00:00 2001 From: Middledot <78228142+Middledot@users.noreply.github.com> Date: Wed, 29 Nov 2023 12:25:50 -0500 Subject: [PATCH 4/4] Apple code suggestion Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Middledot <78228142+Middledot@users.noreply.github.com> --- discord/ext/commands/core.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/ext/commands/core.py b/discord/ext/commands/core.py index cd1b274004..4adb27cad0 100644 --- a/discord/ext/commands/core.py +++ b/discord/ext/commands/core.py @@ -564,11 +564,11 @@ async def dispatch_error(self, ctx: Context, error: Exception) -> None: async def transform(self, ctx: Context, param: inspect.Parameter) -> Any: if isinstance(param.annotation, Option): - required = param.annotation.required or param.annotation.default is None default = param.annotation.default + required = param.annotation.required or default is None else: - required = param.default is param.empty default = param.default + required = default is param.empty converter = get_converter(param) consume_rest_is_special = (