@@ -93,6 +93,52 @@ async def get_all_commands(bot_id,
9393 return await resp .json ()
9494
9595
96+ async def remove_all_commands (slash ):
97+ """
98+ Remove all slash commands.
99+
100+ :param slash: Instance of SlashCommand.
101+ :type slash: SlashCommand
102+ """
103+
104+ await remove_all_commands_in (slash , 'global' )
105+
106+ for guild in slash ._discord .guilds :
107+ try : await remove_all_commands_in (slash , guild .id )
108+ except RequestFailure :
109+ pass
110+
111+
112+ async def remove_all_commands_in (slash , area ):
113+ """
114+ Remove all slash commands in area.
115+
116+ :param slash: Instance of SlashCommand.
117+ :type slash: SlashCommand
118+ :param area: 'global' or guild ID where removing all commands.
119+ :type area: Union[str, int]
120+ """
121+ await slash ._discord .wait_until_ready () # In case commands are still not registered to SlashCommand.
122+
123+ slash .logger .info ("Removing commands..." )
124+
125+ commands = await get_all_commands (
126+ slash ._discord .user .id ,
127+ slash ._discord .http .token ,
128+ None if area == 'global' else area
129+ )
130+
131+ for command in commands :
132+ await remove_slash_command (
133+ slash ._discord .user .id ,
134+ slash ._discord .http .token ,
135+ None if area == 'global' else area ,
136+ command ['id' ]
137+ )
138+
139+ slash .logger .info ("Completed removing all commands !" )
140+
141+
96142def create_option (name : str ,
97143 description : str ,
98144 option_type : int ,
0 commit comments