@@ -341,6 +341,7 @@ def add_slash_command(self,
341341 description : str = None ,
342342 guild_ids : typing .List [int ] = None ,
343343 options : list = None ,
344+ connector : dict = None ,
344345 has_subcommands : bool = False ):
345346 """
346347 Registers slash command to SlashCommand.
@@ -355,6 +356,8 @@ def add_slash_command(self,
355356 :type guild_ids: List[int]
356357 :param options: Options of the slash command. This will affect ``auto_convert`` and command data at Discord API. Default ``None``.
357358 :type options: list
359+ :param connector: Kwargs connector for the command. Default ``None``.
360+ :type connector: dict
358361 :param has_subcommands: Whether it has subcommand. Default ``False``.
359362 :type has_subcommands: bool
360363 """
@@ -379,6 +382,7 @@ def add_slash_command(self,
379382 "description" : description ,
380383 "guild_ids" : guild_ids ,
381384 "api_options" : options ,
385+ "connector" : connector or {},
382386 "has_subcommands" : has_subcommands
383387 }
384388 self .commands [name ] = model .CommandObject (name , _cmd )
@@ -393,7 +397,8 @@ def add_subcommand(self,
393397 base_description : str = None ,
394398 subcommand_group_description : str = None ,
395399 guild_ids : typing .List [int ] = None ,
396- options : list = None ):
400+ options : list = None ,
401+ connector : dict = None ):
397402 """
398403 Registers subcommand to SlashCommand.
399404
@@ -415,6 +420,8 @@ def add_subcommand(self,
415420 :type guild_ids: List[int]
416421 :param options: Options of the subcommand. This will affect ``auto_convert`` and command data at Discord API. Default ``None``.
417422 :type options: list
423+ :param connector: Kwargs connector for the command. Default ``None``.
424+ :type connector: dict
418425 """
419426 base = base .lower ()
420427 subcommand_group = subcommand_group .lower () if subcommand_group else subcommand_group
@@ -436,6 +443,7 @@ def add_subcommand(self,
436443 "description" : base_description ,
437444 "guild_ids" : guild_ids ,
438445 "api_options" : [],
446+ "connector" : {},
439447 "has_subcommands" : True
440448 }
441449 _sub = {
@@ -445,7 +453,8 @@ def add_subcommand(self,
445453 "base_desc" : base_description ,
446454 "sub_group_desc" : subcommand_group_description ,
447455 "guild_ids" : guild_ids ,
448- "api_options" : options
456+ "api_options" : options ,
457+ "connector" : connector or {}
449458 }
450459 if base not in self .commands :
451460 self .commands [base ] = model .CommandObject (base , _cmd )
@@ -474,7 +483,8 @@ def slash(self,
474483 description : str = None ,
475484 guild_id : int = None ,
476485 guild_ids : typing .List [int ] = None ,
477- options : typing .List [dict ] = None ):
486+ options : typing .List [dict ] = None ,
487+ connector : dict = None ):
478488 """
479489 Decorator that registers coroutine as a slash command.\n
480490 All decorator args must be passed as keyword-only args.\n
@@ -502,6 +512,20 @@ async def _slash(ctx): # Normal usage.
502512 async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
503513 await ctx.send(content=str(random.choice([choice1, choice2])))
504514
515+ To format the connector, follow this example.
516+
517+ .. code-block:: python
518+
519+ {
520+ "example-arg": "example_arg",
521+ "시간": "hour"
522+ # Formatting connector is required for
523+ # using other than english for option parameter name
524+ # for in case.
525+ }
526+
527+ Set discord UI's parameter name as key, and set command coroutine's arg name as value.
528+
505529 :param name: Name of the slash command. Default name of the coroutine.
506530 :type name: str
507531 :param description: Description of the slash command. Default ``None``.
@@ -512,13 +536,15 @@ async def _pick(ctx, choice1, choice2): # Command with 1 or more args.
512536 :type guild_ids: List[int]
513537 :param options: Options of the slash command. This will affect ``auto_convert`` and command data at Discord API. Default ``None``.
514538 :type options: List[dict]
539+ :param connector: Kwargs connector for the command. Default ``None``.
540+ :type connector: dict
515541 """
516542 if guild_id :
517543 self .logger .warning ("`guild_id` is deprecated! `Use guild_ids` instead." )
518544 guild_ids = [guild_id ]
519545
520546 def wrapper (cmd ):
521- self .add_slash_command (cmd , name , description , guild_ids , options )
547+ self .add_slash_command (cmd , name , description , guild_ids , options , connector )
522548 return cmd
523549
524550 return wrapper
@@ -534,7 +560,8 @@ def subcommand(self,
534560 subcommand_group_description : str = None ,
535561 sub_group_desc : str = None ,
536562 guild_ids : typing .List [int ] = None ,
537- options : typing .List [dict ] = None ):
563+ options : typing .List [dict ] = None ,
564+ connector : dict = None ):
538565 """
539566 Decorator that registers subcommand.\n
540567 Unlike discord.py, you don't need base command.\n
@@ -582,29 +609,32 @@ async def _group_kick_user(ctx, user):
582609 :type guild_ids: List[int]
583610 :param options: Options of the subcommand. This will affect ``auto_convert`` and command data at Discord API. Default ``None``.
584611 :type options: List[dict]
612+ :param connector: Kwargs connector for the command. Default ``None``.
613+ :type connector: dict
585614 """
586615 base_description = base_description or base_desc
587616 subcommand_group_description = subcommand_group_description or sub_group_desc
588617
589618 def wrapper (cmd ):
590- self .add_subcommand (cmd , base , subcommand_group , name , description , base_description , subcommand_group_description , guild_ids , options )
619+ self .add_subcommand (cmd , base , subcommand_group , name , description , base_description , subcommand_group_description , guild_ids , options , connector )
591620 return cmd
592621
593622 return wrapper
594623
595- async def process_options (self , guild : discord .Guild , options : list ) -> dict :
624+ async def process_options (self , guild : discord .Guild , options : list , connector : dict ) -> dict :
596625 """
597626 Processes Role, User, and Channel option types to discord.py's models.
598627
599628 :param guild: Guild of the command message.
600629 :type guild: discord.Guild
601630 :param options: Dict of options.
602631 :type options: list
632+ :param connector: Kwarg connector.
603633 :return: Union[list, dict]
604634 """
605635
606636 if not guild or not isinstance (guild , discord .Guild ):
607- return {x ["name" ]: x ["value" ] for x in options }
637+ return {connector . get ( x [ "name" ]) or x ["name" ]: x ["value" ] for x in options }
608638
609639 converters = [
610640 # If extra converters are added and some needs to fetch it,
@@ -655,7 +685,7 @@ async def process_options(self, guild: discord.Guild, options: list) -> dict:
655685 except (discord .Forbidden , discord .HTTPException , discord .NotFound ): # Just in case.
656686 self .logger .warning ("Failed fetching discord object! Passing ID instead." )
657687 processed = int (x ["value" ])
658- to_return [x ["name" ]] = processed
688+ to_return [connector . get ( x [ "name" ]) or x ["name" ]] = processed
659689 return to_return
660690
661691 async def invoke_command (self , func , ctx , args ):
@@ -719,7 +749,7 @@ async def on_socket_response(self, msg):
719749 if "value" not in x :
720750 return await self .handle_subcommand (ctx , to_use )
721751
722- args = await self .process_options (ctx .guild , to_use ["data" ]["options" ]) \
752+ args = await self .process_options (ctx .guild , to_use ["data" ]["options" ], selected_cmd . connector ) \
723753 if "options" in to_use ["data" ] else []
724754
725755 self ._discord .dispatch ("slash_command" , ctx )
@@ -752,13 +782,13 @@ async def handle_subcommand(self, ctx: context.SlashContext, data: dict):
752782 return
753783 ctx .subcommand_group = sub_group
754784 selected = base [sub_name ][sub_group ]
755- args = await self .process_options (ctx .guild , x ["options" ]) \
785+ args = await self .process_options (ctx .guild , x ["options" ], selected . connector ) \
756786 if "options" in x else []
757787 self ._discord .dispatch ("slash_command" , ctx )
758788 await self .invoke_command (selected , ctx , args )
759789 return
760790 selected = base [sub_name ]
761- args = await self .process_options (ctx .guild , sub_opts ) \
791+ args = await self .process_options (ctx .guild , sub_opts , selected . connector ) \
762792 if "options" in sub else []
763793 self ._discord .dispatch ("slash_command" , ctx )
764794 await self .invoke_command (selected , ctx , args )
0 commit comments