diff --git a/discord/commands/core.py b/discord/commands/core.py index a5124654b3..125c23ac0f 100644 --- a/discord/commands/core.py +++ b/discord/commands/core.py @@ -56,7 +56,7 @@ from ..enums import SlashCommandOptionType, ChannelType from ..errors import ValidationError, ClientException from ..member import Member -from ..message import Message +from ..message import Attachment, Message from ..user import User from ..utils import find, get_or_fetch, async_all, utcnow @@ -752,6 +752,11 @@ async def _invoke(self, ctx: ApplicationContext) -> None: elif op.input_type == SlashCommandOptionType.string and (converter := op.converter) is not None: arg = await converter.convert(converter, ctx, arg) + elif op.input_type == SlashCommandOptionType.attachment: + _data = ctx.interaction.data["resolved"]["attachments"][arg] + _data["id"] = int(arg) + arg = Attachment(state=ctx.interaction._state, data=_data) + kwargs[op._parameter_name] = arg for o in self.options: diff --git a/discord/enums.py b/discord/enums.py index 1c90a8dcfb..6f657f3215 100644 --- a/discord/enums.py +++ b/discord/enums.py @@ -665,6 +665,8 @@ def from_datatype(cls, datatype): return cls.channel if datatype.__name__ == "Role": return cls.role + if datatype.__name__ == "Attachment": + return cls.attachment if datatype.__name__ == "Mentionable": return cls.mentionable diff --git a/discord/types/interactions.py b/discord/types/interactions.py index 716427494e..54b427eb4a 100644 --- a/discord/types/interactions.py +++ b/discord/types/interactions.py @@ -26,6 +26,8 @@ from __future__ import annotations from typing import Optional, TYPE_CHECKING, Dict, TypedDict, Union, List, Literal + +from .message import Attachment from .snowflake import Snowflake from .components import Component, ComponentType from .embed import Embed @@ -57,7 +59,7 @@ class _ApplicationCommandOptionOptional(TypedDict, total=False): options: List[ApplicationCommandOption] -ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10] +ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11] class ApplicationCommandOption(_ApplicationCommandOptionOptional): @@ -122,7 +124,7 @@ class _ApplicationCommandInteractionDataOptionBoolean(_ApplicationCommandInterac class _ApplicationCommandInteractionDataOptionSnowflake(_ApplicationCommandInteractionDataOption): - type: Literal[6, 7, 8, 9] + type: Literal[6, 7, 8, 9, 11] value: Snowflake @@ -153,6 +155,7 @@ class ApplicationCommandInteractionDataResolved(TypedDict, total=False): members: Dict[Snowflake, Member] roles: Dict[Snowflake, Role] channels: Dict[Snowflake, ApplicationCommandResolvedPartialChannel] + attachments: Dict[Snowflake, Attachment] class _ApplicationCommandInteractionDataOptional(TypedDict, total=False): diff --git a/discord/types/message.py b/discord/types/message.py index ea14695f77..e4cfa89b72 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -25,7 +25,7 @@ from __future__ import annotations -from typing import List, Literal, Optional, TypedDict, Union +from typing import List, Literal, Optional, TypedDict, Union, TYPE_CHECKING from .snowflake import Snowflake, SnowflakeList from .member import Member, UserWithMember from .user import User @@ -33,9 +33,11 @@ from .embed import Embed from .channel import ChannelType from .components import Component -from .interactions import MessageInteraction from .sticker import StickerItem +if TYPE_CHECKING: + from .interactions import MessageInteraction + class ChannelMention(TypedDict): id: Snowflake