From 7e7cbdd24f45d936f12b50987a827a3db7828969 Mon Sep 17 00:00:00 2001 From: Paillat Date: Tue, 29 Oct 2024 16:52:52 +0100 Subject: [PATCH] fix: :bug: Union type cannot be used in `ctx`. (#2611) --- CHANGELOG.md | 2 ++ discord/commands/options.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index daf082ae66..08cb7d9391 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -48,6 +48,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2595](https://github.com/Pycord-Development/pycord/pull/2595)) - Fixed `BucketType.category` cooldown commands not functioning correctly in private channels. ([#2603](https://github.com/Pycord-Development/pycord/pull/2603)) +- Fixed `SlashCommand`'s `ctx` parameter couldn't be `Union` type. + ([#2611](https://github.com/Pycord-Development/pycord/pull/2611)) ### Changed diff --git a/discord/commands/options.py b/discord/commands/options.py index 382067421f..4b35a080d9 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -39,6 +39,7 @@ Thread, VoiceChannel, ) +from ..commands import ApplicationContext from ..enums import ChannelType from ..enums import Enum as DiscordEnum from ..enums import SlashCommandOptionType @@ -227,6 +228,13 @@ def __init__( else: from ..ext.commands import Converter + if isinstance(input_type, tuple) and any( + issubclass(op, ApplicationContext) for op in input_type + ): + input_type = next( + op for op in input_type if issubclass(op, ApplicationContext) + ) + if ( isinstance(input_type, Converter) or input_type_is_class