@@ -644,7 +644,94 @@ async def edit_command(self, old_name, typ: Literal["slash", 1, "user", 2, "mess
644644 else :
645645 await self .create_command (command )
646646 self ._set_command (old_name , command )
647-
647+ async def edit_subcommand (self , base_names , old_name , guild_id = MISSING , * , name , description , options , guild_ids , default_permission , guild_permissions , callback = MISSING ):
648+ """
649+ Edits a subcommand
650+
651+ Parameters
652+ ----------
653+ base_names: List[:class:`str`] | :class:`str`
654+ The base_names of the command
655+ old_name: :class:`str`
656+ The original name of the command
657+ guild_id: :class:`[type]`, optional
658+ The guild id of the command where the changes should be applied; default ``MISSING``
659+ name: :class:`str`, optional
660+ The new name of the command
661+ description: :class:`str`, optional
662+ The new description of the command
663+ options: List[:class:`~SlashOption`], optional
664+ The new options for the command
665+ guild_ids: List[:class:`int` | :class:`str`], optional
666+ The list of new guild_ids where the command is available
667+ default_permission: :class:`bool`, optional
668+ The new default permissions for the command
669+ guild_permissions: :class:`dict`, optional
670+ The new guild permissions for the command
671+ callback: :class:`function`, optional, optional
672+ The new command callback; default ``MISSING``
673+
674+ Raises
675+ ------
676+ :raises: :class:`NotFound` : When a command in the internal cache doesn't exsist
677+ :raises: :class:`NotFound` : When a command in the api doesn't exist
678+
679+ """
680+ if isinstance (base_names , str ):
681+ base_names = [base_names ]
682+ base = self .gather_commands ()[base_names [0 ]]
683+ origin_base = base
684+ if len (base_names ) > 1 and isinstance (base , dict ):
685+ base = get (base .options , base_names [1 ], lambda x : x .getattr ("name" ))
686+ op : SlashOption = get (base , old_name , lambda x : x .getattr ("name" ))
687+ sub = SlashSubcommand .from_data (op .to_dict ())
688+
689+ if guild_id is not MISSING :
690+ api_command = await self ._get_guild_api_command (old_name , CommandType .SLASH , guild_id )
691+ else :
692+ api_command = await self ._get_global_api_command (old_name , CommandType .Slash )
693+
694+ if name is not None :
695+ sub .name = name
696+ if description is not None :
697+ sub .description = description
698+ if options is not None :
699+ sub .options = options
700+ if guild_ids is not None :
701+ sub .guild_ids = guild_ids
702+ if default_permission is not None :
703+ sub .default_permission = default_permission
704+ if guild_permissions is not None :
705+ sub .guild_permissions = guild_permissions
706+ if callback is not MISSING :
707+ sub .callback = callback
708+
709+ base .guild_ids = sub .guild_ids
710+ base .guild_permissions = sub .guild_permissions
711+ base .default_permission = default_permission
712+
713+ # When command only should be edited in one guild
714+ if guild_id is not MISSING and guild_ids is MISSING or sub .guild_ids == guild_ids :
715+ await edit_guild_command (api_command ["id" ], self ._discord , guild_id , base .to_dict (), sub .guild_permissions .get (guild_id ))
716+ # When guild_ids were changed
717+ elif guild_ids is not MISSING and guild_ids != origin_base .guild_ids :
718+ for x in guild_ids :
719+ await self .add_guild_command (base , x )
720+ # When guild command is changed to global command
721+ elif guild_id is not MISSING and guild_ids is MISSING and base .guild_ids is not MISSING :
722+ for x in base .guild_ids :
723+ com = await self ._get_guild_api_command (base .name , base .command_type , x )
724+ await delete_guild_command (self ._discord , com ["id" ], x )
725+ await self .add_global_command (base )
726+ # When global command is changed to guild command
727+ elif origin_base .guild_ids is MISSING and base .guild_ids is not MISSING :
728+ com = await self ._get_global_api_command (origin_base .name , origin_base .command_type )
729+ await delete_global_command (self ._discord , com ["id" ])
730+ await self .create_command (base )
731+ else :
732+ await self .create_command (base )
733+ self ._set_command (old_name , sub )
734+
648735 def _get_command (self , name , typ : Literal ["slash" , 1 , "user" , 2 , "message" , 3 ]) -> SlashCommand :
649736 typ = CommandType .from_string (typ )
650737 if typ == CommandType .SLASH :
0 commit comments