From b4fa1f3dc0d23393378d2b3035e28b684290c10a Mon Sep 17 00:00:00 2001 From: Dasupergrasskakjd Date: Tue, 26 Dec 2023 01:16:22 +0000 Subject: [PATCH 1/7] Update core.py and changelog --- CHANGELOG.md | 2 ++ discord/commands/core.py | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ece1cf3d2..b64c4f8354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -203,6 +203,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2257](https://github.com/Pycord-Development/pycord/issues/2257)) - Fixed `AuditLogIterator` not respecting the `after` parameter. ([#2295](https://github.com/Pycord-Development/pycord/issues/2295)) +- Fixed `MISSING` attribute of command under a subcommand group under a command group + ([#2302](https://github.com/Pycord-Development/pycord/issues/2302)) ## [2.4.1] - 2023-03-20 diff --git a/discord/commands/core.py b/discord/commands/core.py index c7bd4efd40..5962df01e0 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -254,7 +254,7 @@ async def __call__(self, ctx, *args, **kwargs): convert the arguments beforehand, so take care to pass the correct arguments in. """ - if self.cog is not None: + if self.cog is not None and self.cog is not MISSING: return await self.callback(self.cog, ctx, *args, **kwargs) return await self.callback(ctx, *args, **kwargs) @@ -392,7 +392,7 @@ async def can_run(self, ctx: ApplicationContext) -> bool: predicates = self.parent.checks + predicates cog = self.cog - if cog is not None: + if cog is not None and cog is not MISSING: local_check = cog._get_overridden_method(cog.cog_check) if local_check is not None: ret = await maybe_coroutine(local_check, ctx) @@ -414,13 +414,13 @@ async def dispatch_error(self, ctx: ApplicationContext, error: Exception) -> Non pass else: injected = wrap_callback(coro) - if cog is not None: + if cog is not None and cog is not MISSING: await injected(cog, ctx, error) else: await injected(ctx, error) try: - if cog is not None: + if cog is not None and cog is not MISSING: local = cog.__class__._get_overridden_method(cog.cog_command_error) if local is not None: wrapped = wrap_callback(local) @@ -544,7 +544,7 @@ async def call_after_hooks(self, ctx: ApplicationContext) -> None: await self._after_invoke(ctx) # type: ignore # call the cog local hook if applicable: - if cog is not None: + if cog is not None and cog is not MISSING: hook = cog.__class__._get_overridden_method(cog.cog_after_invoke) if hook is not None: await hook(ctx) @@ -998,7 +998,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None: if o._parameter_name not in kwargs: kwargs[o._parameter_name] = o.default - if self.cog is not None: + if self.cog is not None and self.cog is not MISSING: await self.callback(self.cog, ctx, **kwargs) elif self.parent is not None and self.attached_to_group is True: await self.callback(self.parent, ctx, **kwargs) From e9f6b945993906a8589788d01afcccc69451a20f Mon Sep 17 00:00:00 2001 From: Dasupergrasskakjd Date: Tue, 26 Dec 2023 23:52:33 +0000 Subject: [PATCH 2/7] Update core.py --- discord/commands/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/commands/core.py b/discord/commands/core.py index 5962df01e0..c81f18ac7b 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -254,7 +254,7 @@ async def __call__(self, ctx, *args, **kwargs): convert the arguments beforehand, so take care to pass the correct arguments in. """ - if self.cog is not None and self.cog is not MISSING: + if self.cog: return await self.callback(self.cog, ctx, *args, **kwargs) return await self.callback(ctx, *args, **kwargs) @@ -392,7 +392,7 @@ async def can_run(self, ctx: ApplicationContext) -> bool: predicates = self.parent.checks + predicates cog = self.cog - if cog is not None and cog is not MISSING: + if cog: local_check = cog._get_overridden_method(cog.cog_check) if local_check is not None: ret = await maybe_coroutine(local_check, ctx) @@ -414,13 +414,13 @@ async def dispatch_error(self, ctx: ApplicationContext, error: Exception) -> Non pass else: injected = wrap_callback(coro) - if cog is not None and cog is not MISSING: + if cog: await injected(cog, ctx, error) else: await injected(ctx, error) try: - if cog is not None and cog is not MISSING: + if cog: local = cog.__class__._get_overridden_method(cog.cog_command_error) if local is not None: wrapped = wrap_callback(local) @@ -544,7 +544,7 @@ async def call_after_hooks(self, ctx: ApplicationContext) -> None: await self._after_invoke(ctx) # type: ignore # call the cog local hook if applicable: - if cog is not None and cog is not MISSING: + if cog: hook = cog.__class__._get_overridden_method(cog.cog_after_invoke) if hook is not None: await hook(ctx) @@ -998,7 +998,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None: if o._parameter_name not in kwargs: kwargs[o._parameter_name] = o.default - if self.cog is not None and self.cog is not MISSING: + if self.cog: await self.callback(self.cog, ctx, **kwargs) elif self.parent is not None and self.attached_to_group is True: await self.callback(self.parent, ctx, **kwargs) From e29f7f0f124a767f0990a3039e2ed5cdb92f32bd Mon Sep 17 00:00:00 2001 From: Dasupergrasskakjd Date: Tue, 2 Jan 2024 13:58:22 +0000 Subject: [PATCH 3/7] Update core.py --- discord/commands/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/commands/core.py b/discord/commands/core.py index c81f18ac7b..0a5e1fa457 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -1162,7 +1162,7 @@ def __init__( self._before_invoke = None self._after_invoke = None - self.cog = MISSING + self.cog = None self.id = None # Permissions From 3f0168cf7f601d099cdfa152367d210c31cd089c Mon Sep 17 00:00:00 2001 From: Dasupergrasskakjd Date: Tue, 2 Jan 2024 14:37:54 +0000 Subject: [PATCH 4/7] Update core.py --- discord/commands/core.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/discord/commands/core.py b/discord/commands/core.py index 0a5e1fa457..e3c904c1af 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -254,7 +254,7 @@ async def __call__(self, ctx, *args, **kwargs): convert the arguments beforehand, so take care to pass the correct arguments in. """ - if self.cog: + if self.cog is not None: return await self.callback(self.cog, ctx, *args, **kwargs) return await self.callback(ctx, *args, **kwargs) @@ -392,7 +392,7 @@ async def can_run(self, ctx: ApplicationContext) -> bool: predicates = self.parent.checks + predicates cog = self.cog - if cog: + if cog is not None: local_check = cog._get_overridden_method(cog.cog_check) if local_check is not None: ret = await maybe_coroutine(local_check, ctx) @@ -414,13 +414,13 @@ async def dispatch_error(self, ctx: ApplicationContext, error: Exception) -> Non pass else: injected = wrap_callback(coro) - if cog: + if cog is not None: await injected(cog, ctx, error) else: await injected(ctx, error) try: - if cog: + if cog is not None: local = cog.__class__._get_overridden_method(cog.cog_command_error) if local is not None: wrapped = wrap_callback(local) @@ -544,7 +544,7 @@ async def call_after_hooks(self, ctx: ApplicationContext) -> None: await self._after_invoke(ctx) # type: ignore # call the cog local hook if applicable: - if cog: + if cog is not None: hook = cog.__class__._get_overridden_method(cog.cog_after_invoke) if hook is not None: await hook(ctx) @@ -998,7 +998,7 @@ async def _invoke(self, ctx: ApplicationContext) -> None: if o._parameter_name not in kwargs: kwargs[o._parameter_name] = o.default - if self.cog: + if self.cog is not None: await self.callback(self.cog, ctx, **kwargs) elif self.parent is not None and self.attached_to_group is True: await self.callback(self.parent, ctx, **kwargs) From 81a79cf7fa90f8f1e5d7ec51684c20eb68119346 Mon Sep 17 00:00:00 2001 From: Dorukyum Date: Wed, 3 Jan 2024 19:26:14 +0300 Subject: [PATCH 5/7] chore: update changelog --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c2579ed8d8..2255aaf361 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -205,7 +205,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2295](https://github.com/Pycord-Development/pycord/issues/2295)) - Fixed `AttributeError` when failing to establish initial websocket connection. ([#2301](https://github.com/Pycord-Development/pycord/pull/2301)) -- Fixed `MISSING` attribute of command under a subcommand group under a command group +- Fixed `AttributeError` caused by `command.cog` being `MISSING`. ([#2302](https://github.com/Pycord-Development/pycord/issues/2302)) ## [2.4.1] - 2023-03-20 From 480e573236a954cad7fd322cd52b7e981baf804c Mon Sep 17 00:00:00 2001 From: Dorukyum Date: Wed, 3 Jan 2024 19:29:54 +0300 Subject: [PATCH 6/7] fix: remove all references to cog being MISSING --- discord/commands/core.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/discord/commands/core.py b/discord/commands/core.py index e3c904c1af..aff52c8108 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -846,7 +846,7 @@ def _is_typing_annotated(self, annotation): @property def cog(self): - return getattr(self, "_cog", MISSING) + return getattr(self, "_cog", None) @cog.setter def cog(self, val): @@ -1238,10 +1238,7 @@ def to_dict(self) -> dict: return as_dict def add_command(self, command: SlashCommand) -> None: - # check if subcommand has no cog set - # also check if cog is MISSING because it - # might not have been set by the cog yet - if command.cog is MISSING and self.cog is not MISSING: + if command.cog is None and self.cog is not None: command.cog = self.cog self.subcommands.append(command) From 2e3189403bf144abcfc282289412b4bd3809faac Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Wed, 3 Jan 2024 19:40:54 +0300 Subject: [PATCH 7/7] Update CHANGELOG.md Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2255aaf361..fea137c75a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -206,7 +206,7 @@ These changes are available on the `master` branch, but have not yet been releas - Fixed `AttributeError` when failing to establish initial websocket connection. ([#2301](https://github.com/Pycord-Development/pycord/pull/2301)) - Fixed `AttributeError` caused by `command.cog` being `MISSING`. - ([#2302](https://github.com/Pycord-Development/pycord/issues/2302)) + ([#2303](https://github.com/Pycord-Development/pycord/issues/2303)) ## [2.4.1] - 2023-03-20