diff --git a/CHANGELOG.md b/CHANGELOG.md index 6211979f06..db969726cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2938](https://github.com/Pycord-Development/pycord/pull/2938)) - Fixed a KeyError when a text input is left blank in a modal. ([#2938](https://github.com/Pycord-Development/pycord/pull/2938)) +- Fixed `TypeError` when using Python 3.12+ `type` syntax for typing slash command + parameters. ([#2952](https://github.com/Pycord-Development/pycord/pull/2952)) ### Removed diff --git a/discord/commands/options.py b/discord/commands/options.py index c3bfafe888..ac8e4d3a6d 100644 --- a/discord/commands/options.py +++ b/discord/commands/options.py @@ -28,7 +28,15 @@ import logging import types from enum import Enum -from typing import TYPE_CHECKING, Literal, Optional, Type, Union, get_args +from typing import ( + TYPE_CHECKING, + Literal, + Optional, + Type, + TypeAliasType, + Union, + get_args, +) from ..abc import GuildChannel, Mentionable from ..channel import ( @@ -197,6 +205,7 @@ def __init__( if self.name is not None: self.name = str(self.name) self._parameter_name = self.name # default + input_type = self._parse_type_alias(input_type) input_type = self._strip_none_type(input_type) self._raw_type: InputType | tuple = input_type @@ -367,6 +376,12 @@ def __init__( if input_type is None: raise TypeError("input_type cannot be NoneType.") + @staticmethod + def _parse_type_alias(input_type: InputType) -> InputType: + if isinstance(input_type, TypeAliasType): + return input_type.__value__ + return input_type + @staticmethod def _strip_none_type(input_type): if isinstance(input_type, SlashCommandOptionType):