2626
2727import interactions .api .events as events
2828import interactions .client .const as constants
29+ from interactions .models .internal .callback import CallbackObject
2930from interactions .api .events import BaseEvent , RawGatewayEvent , processors
3031from interactions .api .events .internal import CallbackAdded
3132from interactions .api .gateway .gateway import GatewayClient
9091from interactions .models .discord .file import UPLOADABLE_TYPE
9192from interactions .models .discord .snowflake import Snowflake , to_snowflake_list
9293from interactions .models .internal .active_voice_state import ActiveVoiceState
93- from interactions .models .internal .application_commands import ContextMenu , ModalCommand
94+ from interactions .models .internal .application_commands import ContextMenu , ModalCommand , GlobalAutoComplete
9495from interactions .models .internal .auto_defer import AutoDefer
9596from interactions .models .internal .command import BaseCommand
9697from interactions .models .internal .context import (
@@ -378,6 +379,7 @@ def __init__(
378379 """A dictionary of registered application commands in a tree"""
379380 self ._component_callbacks : Dict [str , Callable [..., Coroutine ]] = {}
380381 self ._modal_callbacks : Dict [str , Callable [..., Coroutine ]] = {}
382+ self ._global_autocompletes : Dict [str , GlobalAutoComplete ] = {}
381383 self .processors : Dict [str , Callable [..., Coroutine ]] = {}
382384 self .__modules = {}
383385 self .ext : Dict [str , Extension ] = {}
@@ -1256,6 +1258,15 @@ def add_modal_callback(self, command: ModalCommand) -> None:
12561258 self ._modal_callbacks [listener ] = command
12571259 continue
12581260
1261+ def add_global_autocomplete (self , callback : GlobalAutoComplete ) -> None :
1262+ """
1263+ Add a global autocomplete to the client.
1264+
1265+ Args:
1266+ callback: The autocomplete to add
1267+ """
1268+ self ._global_autocompletes [callback .option_name ] = callback
1269+
12591270 def add_command (self , func : Callable ) -> None :
12601271 """
12611272 Add a command to the client.
@@ -1271,6 +1282,8 @@ def add_command(self, func: Callable) -> None:
12711282 self .add_interaction (func )
12721283 elif isinstance (func , Listener ):
12731284 self .add_listener (func )
1285+ elif isinstance (func , GlobalAutoComplete ):
1286+ self .add_global_autocomplete (func )
12741287 elif not isinstance (func , BaseCommand ):
12751288 raise TypeError ("Invalid command type" )
12761289
@@ -1302,12 +1315,10 @@ def process(callables, location: str) -> None:
13021315 self .logger .debug (f"{ added } callbacks have been loaded from { location } ." )
13031316
13041317 main_commands = [
1305- obj for _ , obj in inspect .getmembers (sys .modules ["__main__" ]) if isinstance (obj , ( BaseCommand , Listener ) )
1318+ obj for _ , obj in inspect .getmembers (sys .modules ["__main__" ]) if isinstance (obj , CallbackObject )
13061319 ]
13071320 client_commands = [
1308- obj .copy_with_binding (self )
1309- for _ , obj in inspect .getmembers (self )
1310- if isinstance (obj , (BaseCommand , Listener ))
1321+ obj .copy_with_binding (self ) for _ , obj in inspect .getmembers (self ) if isinstance (obj , CallbackObject )
13111322 ]
13121323 process (main_commands , "__main__" )
13131324 process (client_commands , self .__class__ .__name__ )
@@ -1597,7 +1608,6 @@ async def _dispatch_interaction(self, event: RawGatewayEvent) -> None:
15971608 elif autocomplete := self ._global_autocompletes .get (str (auto_opt .name )):
15981609 callback = autocomplete
15991610 else :
1600- breakpoint ()
16011611 raise ValueError (f"Autocomplete callback for { str (auto_opt .name )} not found" )
16021612
16031613 await self .__dispatch_interaction (
0 commit comments