@@ -52,6 +52,9 @@ def remove(self):
5252 """
5353 Removes :func:`on_socket_response` event listener from discord.py Client.
5454
55+ .. warning::
56+ This is deprecated and will be removed soon.
57+
5558 .. note::
5659 This only works if it is :class:`discord.ext.commands.Bot` or
5760 :class:`discord.ext.commands.AutoShardedBot`.
@@ -61,6 +64,12 @@ def remove(self):
6164 self ._discord .remove_listener (self .on_socket_response )
6265
6366 def get_cog_commands (self , cog : commands .Cog ):
67+ """
68+ Gets slash command from :class:`discord.ext.commands.Cog`.
69+
70+ :param cog: Cog that has slash commands.
71+ :type cog: discord.ext.commands.Cog
72+ """
6473 func_list = [getattr (cog , x ) for x in dir (cog )]
6574 res = [x for x in func_list if
6675 isinstance (x , model .CogCommandObject ) or isinstance (x , model .CogSubcommandObject )]
@@ -92,9 +101,39 @@ def get_cog_commands(self, cog: commands.Cog):
92101 self .subcommands [x .base ][x .name ] = x
93102
94103 def remove_cog_commands (self , cog ):
104+ """
105+ Removes slash command from :class:`discord.ext.commands.Cog`.
106+
107+ :param cog: Cog that has slash commands.
108+ :type cog: discord.ext.commands.Cog
109+ """
95110 func_list = [getattr (cog , x ) for x in dir (cog )]
96111 res = [x for x in func_list if
97112 isinstance (x , model .CogCommandObject ) or isinstance (x , model .CogSubcommandObject )]
113+ for x in res :
114+ if isinstance (x , model .CogCommandObject ):
115+ if x .name not in self .commands .keys ():
116+ continue # Just in case it is removed due to subcommand.
117+ if x .name in self .subcommands .keys ():
118+ self .commands [x .name ].func = None
119+ continue # Let's remove completely when every subcommand is removed.
120+ del self .commands [x .name ]
121+ else :
122+ if x .base not in self .subcommands .keys ():
123+ continue # Just in case...
124+ if x .subcommand_group :
125+ del self .subcommands [x .base ][x .subcommand_group ][x .name ]
126+ if not self .subcommands [x .base ][x .subcommand_group ]:
127+ del self .subcommands [x .base ][x .subcommand_group ]
128+ else :
129+ del self .subcommands [x .base ][x .name ]
130+ if not self .subcommands [x .base ]:
131+ del self .subcommands [x .base ]
132+ if x .base in self .commands .keys ():
133+ if self .commands [x .base ].func :
134+ self .commands [x .base ].has_subcommands = False
135+ else :
136+ del self .commands [x .base ]
98137
99138 async def register_all_commands (self ):
100139 """
0 commit comments