@@ -52,6 +52,9 @@ def remove(self):
52
52
"""
53
53
Removes :func:`on_socket_response` event listener from discord.py Client.
54
54
55
+ .. warning::
56
+ This is deprecated and will be removed soon.
57
+
55
58
.. note::
56
59
This only works if it is :class:`discord.ext.commands.Bot` or
57
60
:class:`discord.ext.commands.AutoShardedBot`.
@@ -61,6 +64,12 @@ def remove(self):
61
64
self ._discord .remove_listener (self .on_socket_response )
62
65
63
66
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
+ """
64
73
func_list = [getattr (cog , x ) for x in dir (cog )]
65
74
res = [x for x in func_list if
66
75
isinstance (x , model .CogCommandObject ) or isinstance (x , model .CogSubcommandObject )]
@@ -92,9 +101,39 @@ def get_cog_commands(self, cog: commands.Cog):
92
101
self .subcommands [x .base ][x .name ] = x
93
102
94
103
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
+ """
95
110
func_list = [getattr (cog , x ) for x in dir (cog )]
96
111
res = [x for x in func_list if
97
112
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 ]
98
137
99
138
async def register_all_commands (self ):
100
139
"""
0 commit comments