diff --git a/discord/abc.py b/discord/abc.py index 104e232c5..81f59b86c 100644 --- a/discord/abc.py +++ b/discord/abc.py @@ -48,7 +48,7 @@ from typing import ( from .object import OLDEST_OBJECT, Object from .context_managers import Typing -from .enums import AppCommandType, ChannelType +from .enums import ApplicationCommandType, ChannelType from .errors import ClientException from .mentions import AllowedMentions from .permissions import PermissionOverwrite, Permissions @@ -163,7 +163,7 @@ async def _purge_helper( @overload def _handle_commands( messageable: Messageable, - type: Literal[AppCommandType.chat_input], + type: Literal[ApplicationCommandType.chat_input], *, query: Optional[str] = ..., limit: Optional[int] = ..., @@ -178,7 +178,7 @@ def _handle_commands( @overload def _handle_commands( messageable: Messageable, - type: Literal[AppCommandType.user], + type: Literal[ApplicationCommandType.user], *, query: Optional[str] = ..., limit: Optional[int] = ..., @@ -193,7 +193,7 @@ def _handle_commands( @overload def _handle_commands( messageable: Message, - type: Literal[AppCommandType.message], + type: Literal[ApplicationCommandType.message], *, query: Optional[str] = ..., limit: Optional[int] = ..., @@ -207,7 +207,7 @@ def _handle_commands( async def _handle_commands( messageable: Union[Messageable, Message], - type: AppCommandType, + type: ApplicationCommandType, *, query: Optional[str] = None, limit: Optional[int] = None, @@ -2424,7 +2424,7 @@ class Messageable: """ return _handle_commands( self, - AppCommandType.chat_input, + ApplicationCommandType.chat_input, query=query, limit=limit, command_ids=command_ids, @@ -2500,7 +2500,7 @@ class Messageable: """ return _handle_commands( self, - AppCommandType.user, + ApplicationCommandType.user, query=query, limit=limit, command_ids=command_ids, diff --git a/discord/commands.py b/discord/commands.py index 76ce28b63..90e349e05 100644 --- a/discord/commands.py +++ b/discord/commands.py @@ -26,7 +26,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Any, Dict, List, Optional, Protocol, Tuple, Type, Union, runtime_checkable -from .enums import AppCommandOptionType, AppCommandType, ChannelType, InteractionType, try_enum +from .enums import ApplicationCommandOptionType, ApplicationCommandType, ChannelType, InteractionType, try_enum from .interactions import _wrapped_interaction from .mixins import Hashable from .permissions import Permissions @@ -76,7 +76,7 @@ class ApplicationCommand(Protocol): The command's name. description: :class:`str` The command's description, if any. - type: :class:`~discord.AppCommandType` + type: :class:`~discord.ApplicationCommandType` The type of application command. dm_permission: :class:`bool` Whether the command is enabled in DMs. @@ -101,7 +101,7 @@ class ApplicationCommand(Protocol): name: str description: str version: int - type: AppCommandType + type: ApplicationCommandType dm_permission: bool nsfw: bool application_id: int @@ -203,7 +203,7 @@ class BaseCommand(ApplicationCommand, Hashable): self.application_id: int = int(data['application_id']) self.id: int = int(data['id']) self.version = int(data['version']) - self.type = try_enum(AppCommandType, data['type']) + self.type = try_enum(ApplicationCommandType, data['type']) application = data.get('application') self.application = state.create_integration_application(application) if application else None @@ -263,25 +263,25 @@ class SlashMixin(ApplicationCommand, Protocol): type = option.type if type in { - AppCommandOptionType.user, - AppCommandOptionType.channel, - AppCommandOptionType.role, - AppCommandOptionType.mentionable, + ApplicationCommandOptionType.user, + ApplicationCommandOptionType.channel, + ApplicationCommandOptionType.role, + ApplicationCommandOptionType.mentionable, }: v = str(v.id) - elif type is AppCommandOptionType.boolean: + elif type is ApplicationCommandOptionType.boolean: v = bool(v) - elif type is AppCommandOptionType.attachment: + elif type is ApplicationCommandOptionType.attachment: files.append(v) v = len(files) - 1 else: v = option._convert(v) - if type is AppCommandOptionType.string: + if type is ApplicationCommandOptionType.string: v = str(v) - elif type is AppCommandOptionType.integer: + elif type is ApplicationCommandOptionType.integer: v = int(v) - elif type is AppCommandOptionType.number: + elif type is ApplicationCommandOptionType.number: v = float(v) options.append({'name': k, 'value': v, 'type': type.value}) @@ -296,10 +296,10 @@ class SlashMixin(ApplicationCommand, Protocol): options = [] children = [] for option in data: - type = try_enum(AppCommandOptionType, option['type']) + type = try_enum(ApplicationCommandOptionType, option['type']) if type in { - AppCommandOptionType.sub_command, - AppCommandOptionType.sub_command_group, + ApplicationCommandOptionType.sub_command, + ApplicationCommandOptionType.sub_command_group, }: children.append(SubCommand(parent=self, data=option)) else: @@ -346,8 +346,8 @@ class UserCommand(BaseCommand): The command's name. description: :class:`str` The command's description, if any. - type: :class:`AppCommandType` - The type of application command. This will always be :attr:`AppCommandType.user`. + type: :class:`ApplicationCommandType` + The type of application command. This will always be :attr:`ApplicationCommandType.user`. dm_permission: :class:`bool` Whether the command is enabled in DMs. nsfw: :class:`bool` @@ -458,8 +458,8 @@ class MessageCommand(BaseCommand): The command's name. description: :class:`str` The command's description, if any. - type: :class:`AppCommandType` - The type of application command. This will always be :attr:`AppCommandType.message`. + type: :class:`ApplicationCommandType` + The type of application command. This will always be :attr:`ApplicationCommandType.message`. dm_permission: :class:`bool` Whether the command is enabled in DMs. nsfw: :class:`bool` @@ -571,7 +571,7 @@ class SlashCommand(BaseCommand, SlashMixin): The command's name. description: :class:`str` The command's description, if any. - type: :class:`AppCommandType` + type: :class:`ApplicationCommandType` The type of application command. dm_permission: :class:`bool` Whether the command is enabled in DMs. @@ -669,8 +669,8 @@ class SubCommand(SlashMixin): The subcommand's name. description: :class:`str` The subcommand's description, if any. - type: :class:`AppCommandType` - The type of application command. Always :attr:`AppCommandType.chat_input`. + type: :class:`ApplicationCommandType` + The type of application command. Always :attr:`ApplicationCommandType.chat_input`. parent: Union[:class:`SlashCommand`, :class:`SubCommand`] The parent command. options: List[:class:`Option`] @@ -695,8 +695,8 @@ class SubCommand(SlashMixin): self._state = parent._state self.parent: Union[SlashCommand, SubCommand] = parent self._parent: SlashCommand = getattr(parent, 'parent', parent) # type: ignore - self.type = AppCommandType.chat_input # Avoid confusion I guess - self._type: AppCommandOptionType = try_enum(AppCommandOptionType, data['type']) + self.type = ApplicationCommandType.chat_input # Avoid confusion I guess + self._type: ApplicationCommandOptionType = try_enum(ApplicationCommandOptionType, data['type']) self._unwrap_options(data.get('options', [])) def __str__(self) -> str: @@ -827,7 +827,7 @@ class SubCommand(SlashMixin): :class:`bool` Whether this command is a group. """ - return self._type is AppCommandOptionType.sub_command_group + return self._type is ApplicationCommandOptionType.sub_command_group @property def application(self): @@ -866,26 +866,26 @@ class Option: The option's name. description: :class:`str` The option's description, if any. - type: :class:`AppCommandOptionType` + type: :class:`ApplicationCommandOptionType` The type of option. required: :class:`bool` Whether the option is required. min_value: Optional[Union[:class:`int`, :class:`float`]] - Minimum value of the option. Only applicable to :attr:`AppCommandOptionType.integer` and :attr:`AppCommandOptionType.number`. + Minimum value of the option. Only applicable to :attr:`ApplicationCommandOptionType.integer` and :attr:`ApplicationCommandOptionType.number`. max_value: Optional[Union[:class:`int`, :class:`float`]] - Maximum value of the option. Only applicable to :attr:`AppCommandOptionType.integer` and :attr:`AppCommandOptionType.number`. + Maximum value of the option. Only applicable to :attr:`ApplicationCommandOptionType.integer` and :attr:`ApplicationCommandOptionType.number`. choices: List[:class:`OptionChoice`] A list of possible choices to choose from. If these are present, you must choose one from them. - Only applicable to :attr:`AppCommandOptionType.string`, :attr:`AppCommandOptionType.integer`, and :attr:`AppCommandOptionType.number`. + Only applicable to :attr:`ApplicationCommandOptionType.string`, :attr:`ApplicationCommandOptionType.integer`, and :attr:`ApplicationCommandOptionType.number`. channel_types: List[:class:`ChannelType`] A list of channel types that you can choose from. If these are present, you must choose a channel that is one of these types. - Only applicable to :attr:`AppCommandOptionType.channel`. + Only applicable to :attr:`ApplicationCommandOptionType.channel`. autocomplete: :class:`bool` Whether the option autocompletes. - Only applicable to :attr:`AppCommandOptionType.string`, :attr:`AppCommandOptionType.integer`, and :attr:`AppCommandOptionType.number`. + Only applicable to :attr:`ApplicationCommandOptionType.string`, :attr:`ApplicationCommandOptionType.integer`, and :attr:`ApplicationCommandOptionType.number`. Always ``False`` if :attr:`choices` are present. """ @@ -904,7 +904,7 @@ class Option: def __init__(self, data): self.name: str = data['name'] self.description: str = data['description'] - self.type: AppCommandOptionType = try_enum(AppCommandOptionType, data['type']) + self.type: ApplicationCommandOptionType = try_enum(ApplicationCommandOptionType, data['type']) self.required: bool = data.get('required', False) self.min_value: Optional[Union[int, float]] = data.get('min_value') self.max_value: Optional[int] = data.get('max_value') @@ -946,14 +946,14 @@ class OptionChoice: __slots__ = ('name', 'value') - def __init__(self, data: Dict[str, str], type: AppCommandOptionType): + def __init__(self, data: Dict[str, str], type: ApplicationCommandOptionType): self.name: str = data['name'] self.value: Union[str, int, float] - if type is AppCommandOptionType.string: + if type is ApplicationCommandOptionType.string: self.value = data['value'] - elif type is AppCommandOptionType.integer: + elif type is ApplicationCommandOptionType.integer: self.value = int(data['value']) - elif type is AppCommandOptionType.number: + elif type is ApplicationCommandOptionType.number: self.value = float(data['value']) def __str__(self) -> str: @@ -968,13 +968,13 @@ class OptionChoice: return value -def _command_factory(command_type: int) -> Tuple[AppCommandType, Type[BaseCommand]]: - value = try_enum(AppCommandType, command_type) - if value is AppCommandType.chat_input: +def _command_factory(command_type: int) -> Tuple[ApplicationCommandType, Type[BaseCommand]]: + value = try_enum(ApplicationCommandType, command_type) + if value is ApplicationCommandType.chat_input: return value, SlashCommand - elif value is AppCommandType.user: + elif value is ApplicationCommandType.user: return value, UserCommand - elif value is AppCommandType.message: + elif value is ApplicationCommandType.message: return value, MessageCommand else: return value, BaseCommand # IDK about this diff --git a/discord/enums.py b/discord/enums.py index a52f68482..aaaf94e65 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -64,7 +64,9 @@ __all__ = ( 'Locale', 'EntityType', 'EventStatus', + 'ApplicationCommandType', 'AppCommandType', + 'ApplicationCommandOptionType', 'AppCommandOptionType', 'RelationshipType', 'HypeSquadHouse', @@ -1055,7 +1057,7 @@ class EventStatus(Enum): cancelled = 4 -class AppCommandOptionType(Enum): +class ApplicationCommandOptionType(Enum): subcommand = 1 sub_command = 1 subcommand_group = 2 @@ -1071,7 +1073,10 @@ class AppCommandOptionType(Enum): attachment = 11 -class AppCommandType(Enum): +AppCommandOptionType = ApplicationCommandOptionType + + +class ApplicationCommandType(Enum): chat_input = 1 user = 2 message = 3 @@ -1080,6 +1085,9 @@ class AppCommandType(Enum): return self.value +AppCommandType = ApplicationCommandType + + class ConnectionType(Enum): battle_net = 'battlenet' contacts = 'contacts' diff --git a/discord/message.py b/discord/message.py index 57a0490d1..e6c25a890 100644 --- a/discord/message.py +++ b/discord/message.py @@ -51,7 +51,7 @@ from .reaction import Reaction from .emoji import Emoji from .partial_emoji import PartialEmoji from .calls import CallMessage -from .enums import MessageType, ChannelType, AppCommandType, try_enum +from .enums import MessageType, ChannelType, ApplicationCommandType, try_enum from .errors import HTTPException from .components import _component_factory from .embeds import Embed @@ -2359,7 +2359,7 @@ class Message(PartialMessage, Hashable): """ return _handle_commands( self, - AppCommandType.message, + ApplicationCommandType.message, query=query, limit=limit, command_ids=command_ids, diff --git a/discord/types/integration.py b/discord/types/integration.py index c11c81894..6564d403d 100644 --- a/discord/types/integration.py +++ b/discord/types/integration.py @@ -30,7 +30,7 @@ from typing_extensions import NotRequired from .application import IntegrationApplication, RoleConnectionMetadata from .guild import Guild from .snowflake import Snowflake -from .user import User +from .user import APIUser class IntegrationAccount(TypedDict): @@ -54,7 +54,7 @@ IntegrationType = Literal['twitch', 'youtube', 'discord', 'guild_subscription'] class BaseIntegration(PartialIntegration): enabled: bool - user: NotRequired[User] + user: NotRequired[APIUser] class StreamIntegration(BaseIntegration): diff --git a/docs/api.rst b/docs/api.rst index a6c0a1048..8b69008ce 100644 --- a/docs/api.rst +++ b/docs/api.rst @@ -5483,7 +5483,7 @@ of :class:`enum.Enum`. An alias for :attr:`paragraph`. -.. class:: AppCommandType +.. class:: ApplicationCommandType The type of application command. @@ -5501,7 +5501,7 @@ of :class:`enum.Enum`. A message context menu command. -.. class:: AppCommandOptionType +.. class:: ApplicationCommandOptionType The application command's option type. This is usually the type of parameter an application command takes.