1- from discord .ext .commands import Bot
21from .errors import InvalidEvent , OutOfValidRange , WrongType
32from .slash .errors import AlreadyDeferred , EphemeralDeletion
43from .slash .types import ContextCommand , SlashCommand , SlashPermission , SlashSubcommand
1110from discord .errors import HTTPException
1211from discord .state import ConnectionState
1312
14- import typing
13+ from typing import List , Union , Dict
14+ try :
15+ from typing import Literal
16+ except :
17+ from typing_extensions import Literal
1518
1619logging = setup_logger ("discord-ui" )
1720
@@ -31,7 +34,7 @@ def __init__(self, state, data, user=MISSING, message=None) -> None:
3134 self ._original_payload : dict = data
3235
3336 if user is not MISSING :
34- self .author : typing . Union [discord .Member , discord .User ] = user
37+ self .author : Union [discord .Member , discord .User ] = user
3538 """The user who created the interaction"""
3639 self .application_id : int = data ["application_id" ]
3740 """The ID of the bot application"""
@@ -59,7 +62,7 @@ def guild(self) -> discord.Guild:
5962 """
6063 return self ._state ._get_guild (self .guild_id )
6164 @property
62- def channel (self ) -> typing . Union [discord .TextChannel , discord .DMChannel ]:
65+ def channel (self ) -> Union [discord .TextChannel , discord .DMChannel ]:
6366 """The channel where the interaction was created
6467
6568 :type: :class:`discord.TextChannel` | :class:`discord.DMChannel`
@@ -94,7 +97,7 @@ async def defer(self, hidden=False):
9497
9598 async def respond (self , content = MISSING , * , tts = False , embed = MISSING , embeds = MISSING , file = MISSING , files = MISSING , nonce = MISSING ,
9699 allowed_mentions = MISSING , mention_author = MISSING , components = MISSING , delete_after = MISSING , hidden = False ,
97- ninja_mode = False ) -> typing . Union ['Message' , 'EphemeralMessage' ]:
100+ ninja_mode = False ) -> Union ['Message' , 'EphemeralMessage' ]:
98101 """Responds to the interaction
99102
100103 Parameters
@@ -202,7 +205,7 @@ async def respond(self, content=MISSING, *, tts=False, embed=MISSING, embeds=MIS
202205 return msg
203206
204207 async def send (self , content = None , * , tts = False , embed = MISSING , embeds = MISSING , file = MISSING , files = MISSING , nonce = MISSING ,
205- allowed_mentions = MISSING , mention_author = MISSING , components = MISSING , hidden = False ) -> typing . Union ['Message' , 'EphemeralMessage' ]:
208+ allowed_mentions = MISSING , mention_author = MISSING , components = MISSING , hidden = False ) -> Union ['Message' , 'EphemeralMessage' ]:
206209 """Sends a message to the interaction using a webhook
207210
208211 Parameters
@@ -272,7 +275,7 @@ def __init__(self, data, user, s, msg, client) -> None:
272275 self ._json = s .to_dict ()
273276 self .bot : Bot = client
274277 #region selected_values
275- self .selected_values : typing . List [SelectOption ] = []
278+ self .selected_values : List [SelectOption ] = []
276279 """The list of values which were selected"""
277280 for val in data ["data" ]["values" ]:
278281 for x in self .options :
@@ -303,7 +306,7 @@ def __init__(self, client, command: SlashCommand, data, user, args = None, guild
303306 """The channel where the slash command was used"""
304307 self .guild_ids = guild_ids
305308 """The ids of the guilds where the command is available"""
306- self .args : typing . Dict [str , typing . Union [str , int , bool , discord .Member , discord .TextChannel , discord .Role , float ]] = args
309+ self .args : Dict [str , Union [str , int , bool , discord .Member , discord .TextChannel , discord .Role , float ]] = args
307310 """The options that were received"""
308311 self .permissions : SlashPermission = guild_permissions .get (self .guild_id )
309312 """The permissions for the guild"""
@@ -319,9 +322,9 @@ def __init__(self, client, command: ContextCommand, data, user, param, guild_ids
319322 ContextCommand .__init__ (self , None , "EMPTY" , guild_ids = guild_ids , guild_permissions = guild_permissions )
320323 self .bot : Bot = client
321324 self ._json = command .to_dict ()
322- self .guild_ids : typing . List [int ] = guild_ids
325+ self .guild_ids : List [int ] = guild_ids
323326 """The guild_ids where the command is available"""
324- self .param : typing . Union [Message , discord .Member , discord .User ] = param
327+ self .param : Union [Message , discord .Member , discord .User ] = param
325328 """The parameter that was received"""
326329 self .permissions : SlashPermission = guild_permissions .get (self .guild_id )
327330 """The permissions for the guild"""
@@ -367,7 +370,7 @@ def __init__(self, *, state, channel, data):
367370
368371 self ._state : ConnectionState = None
369372 super ().__init__ (state = state , channel = channel , data = data )
370- self .components : typing . List [typing . Union [Button , LinkButton , SelectMenu ]] = []
373+ self .components : List [Union [Button , LinkButton , SelectMenu ]] = []
371374 """The components in the message
372375
373376 :type: List[]:class:`~Button` | :class:`~LinkButton` | :class:`SelectMenu`]
@@ -377,7 +380,7 @@ def __init__(self, *, state, channel, data):
377380
378381 # region attributes
379382 @property
380- def buttons (self ) -> typing . List [typing . Union [Button , LinkButton ]]:
383+ def buttons (self ) -> List [Union [Button , LinkButton ]]:
381384 """The button components in the message
382385
383386 :type: List[:class:`~Button` | :class:`~LinkButton`]
@@ -386,7 +389,7 @@ def buttons(self) -> typing.List[typing.Union[Button, LinkButton]]:
386389 return [x for x in self .components if type (x ) in [Button , LinkButton ]]
387390 return []
388391 @property
389- def select_menus (self ) -> typing . List [SelectMenu ]:
392+ def select_menus (self ) -> List [SelectMenu ]:
390393 """The select menus components in the message
391394
392395 :type: List[:class:`~SelectMenu`]
@@ -514,7 +517,7 @@ def action_rows(self):
514517
515518 :type: List[:class:`~Button` | :class:`LinkButton` | :class:`SelectMenu`]
516519 """
517- rows : typing . List [typing . List [typing . Union [Button , LinkButton , SelectMenu ]]] = []
520+ rows : List [List [Union [Button , LinkButton , SelectMenu ]]] = []
518521
519522 c_row = []
520523 i = 0
@@ -528,7 +531,7 @@ def action_rows(self):
528531 rows .append (c_row )
529532 return rows
530533
531- async def wait_for (self , event_name : typing . Literal ["select" , "button" ], client , custom_id = MISSING , by = MISSING , check = lambda component : True , timeout = None ) -> typing . Union [PressedButton , SelectedMenu ]:
534+ async def wait_for (self , event_name : Literal ["select" , "button" ], client , custom_id = MISSING , by = MISSING , check = lambda component : True , timeout = None ) -> Union [PressedButton , SelectedMenu ]:
532535 """Waits for a message component to be invoked in this message
533536
534537 Parameters
0 commit comments