Skip to content

Commit 5806985

Browse files
LulalabyizxxrDorukyum
authored
Slash Attachments (#579)
* Note that attachments needs to be implemented GPG Test * add proto for attachment * Attachment base logic (Needs rework) * Update discord/types/interactions.py Co-authored-by: Izhar Ahmad <[email protected]> * Parse received attachment Co-authored-by: Izhar Ahmad <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent 8690471 commit 5806985

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

discord/commands/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
from ..enums import SlashCommandOptionType, ChannelType
5757
from ..errors import ValidationError, ClientException
5858
from ..member import Member
59-
from ..message import Message
59+
from ..message import Attachment, Message
6060
from ..user import User
6161
from ..utils import find, get_or_fetch, async_all, utcnow
6262

@@ -752,6 +752,11 @@ async def _invoke(self, ctx: ApplicationContext) -> None:
752752
elif op.input_type == SlashCommandOptionType.string and (converter := op.converter) is not None:
753753
arg = await converter.convert(converter, ctx, arg)
754754

755+
elif op.input_type == SlashCommandOptionType.attachment:
756+
_data = ctx.interaction.data["resolved"]["attachments"][arg]
757+
_data["id"] = int(arg)
758+
arg = Attachment(state=ctx.interaction._state, data=_data)
759+
755760
kwargs[op._parameter_name] = arg
756761

757762
for o in self.options:

discord/enums.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,8 @@ def from_datatype(cls, datatype):
665665
return cls.channel
666666
if datatype.__name__ == "Role":
667667
return cls.role
668+
if datatype.__name__ == "Attachment":
669+
return cls.attachment
668670
if datatype.__name__ == "Mentionable":
669671
return cls.mentionable
670672

discord/types/interactions.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
from __future__ import annotations
2727

2828
from typing import Optional, TYPE_CHECKING, Dict, TypedDict, Union, List, Literal
29+
30+
from .message import Attachment
2931
from .snowflake import Snowflake
3032
from .components import Component, ComponentType
3133
from .embed import Embed
@@ -57,7 +59,7 @@ class _ApplicationCommandOptionOptional(TypedDict, total=False):
5759
options: List[ApplicationCommandOption]
5860

5961

60-
ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
62+
ApplicationCommandOptionType = Literal[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
6163

6264

6365
class ApplicationCommandOption(_ApplicationCommandOptionOptional):
@@ -122,7 +124,7 @@ class _ApplicationCommandInteractionDataOptionBoolean(_ApplicationCommandInterac
122124

123125

124126
class _ApplicationCommandInteractionDataOptionSnowflake(_ApplicationCommandInteractionDataOption):
125-
type: Literal[6, 7, 8, 9]
127+
type: Literal[6, 7, 8, 9, 11]
126128
value: Snowflake
127129

128130

@@ -153,6 +155,7 @@ class ApplicationCommandInteractionDataResolved(TypedDict, total=False):
153155
members: Dict[Snowflake, Member]
154156
roles: Dict[Snowflake, Role]
155157
channels: Dict[Snowflake, ApplicationCommandResolvedPartialChannel]
158+
attachments: Dict[Snowflake, Attachment]
156159

157160

158161
class _ApplicationCommandInteractionDataOptional(TypedDict, total=False):

discord/types/message.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,19 @@
2525

2626
from __future__ import annotations
2727

28-
from typing import List, Literal, Optional, TypedDict, Union
28+
from typing import List, Literal, Optional, TypedDict, Union, TYPE_CHECKING
2929
from .snowflake import Snowflake, SnowflakeList
3030
from .member import Member, UserWithMember
3131
from .user import User
3232
from .emoji import PartialEmoji
3333
from .embed import Embed
3434
from .channel import ChannelType
3535
from .components import Component
36-
from .interactions import MessageInteraction
3736
from .sticker import StickerItem
3837

38+
if TYPE_CHECKING:
39+
from .interactions import MessageInteraction
40+
3941

4042
class ChannelMention(TypedDict):
4143
id: Snowflake

0 commit comments

Comments
 (0)