@@ -50,6 +50,13 @@ async def sync_tree(self, ctx: commands.Context[commands.Bot], guild: discord.Gu
5050 await self .bot .tree .sync (guild = ctx .guild )
5151 await ctx .reply ("Application command tree synced." )
5252
53+ @sync_tree .error
54+ async def sync_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
55+ if isinstance (error , commands .MissingRequiredArgument ):
56+ await ctx .send (f"Please specify a guild to sync application commands to. { error } " )
57+ else :
58+ logger .error (f"Error syncing application commands: { error } " )
59+
5360 @commands .has_guild_permissions (administrator = True )
5461 @dev .command (
5562 name = "clear_tree" ,
@@ -131,6 +138,22 @@ async def load_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) -> No
131138 await ctx .send (f"Cog { cog } loaded." )
132139 logger .info (f"Cog { cog } loaded." )
133140
141+ @load_cog .error
142+ async def load_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
143+ if isinstance (error , commands .MissingRequiredArgument ):
144+ await ctx .send (f"Please specify an cog to load. { error } " )
145+ elif isinstance (error , commands .ExtensionAlreadyLoaded ):
146+ await ctx .send (f"The specified cog is already loaded. { error } " )
147+ elif isinstance (error , commands .ExtensionNotFound ):
148+ await ctx .send (f"The specified cog is not found. { error } " )
149+ elif isinstance (error , commands .ExtensionFailed ):
150+ await ctx .send (f"Failed to load cog: { error } " )
151+ elif isinstance (error , commands .NoEntryPointError ):
152+ await ctx .send (f"The specified cog does not have a setup function. { error } " )
153+ else :
154+ await ctx .send (f"Failed to load cog: { error } " )
155+ logger .error (f"Failed to load cog: { error } " )
156+
134157 @commands .has_guild_permissions (administrator = True )
135158 @dev .command (
136159 name = "unload_cog" ,
@@ -169,6 +192,15 @@ async def unload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) ->
169192 logger .info (f"Cog { cog } unloaded." )
170193 await ctx .send (f"Cog { cog } unloaded." )
171194
195+ @unload_cog .error
196+ async def unload_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
197+ if isinstance (error , commands .MissingRequiredArgument ):
198+ await ctx .send (f"Please specify an extension to unload. { error } " )
199+ elif isinstance (error , commands .ExtensionNotLoaded ):
200+ await ctx .send (f"That cog is not loaded. { error } " )
201+ else :
202+ logger .error (f"Error unloading cog: { error } " )
203+
172204 @commands .has_guild_permissions (administrator = True )
173205 @dev .command (
174206 name = "reload_cog" ,
@@ -208,14 +240,6 @@ async def reload_cog(self, ctx: commands.Context[commands.Bot], *, cog: str) ->
208240 await ctx .send (f"Cog { cog } reloaded." )
209241 logger .info (f"Cog { cog } reloaded." )
210242
211- @sync_tree .error
212- async def sync_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
213- if isinstance (error , commands .MissingRequiredArgument ):
214- await ctx .send (f"Please specify a guild to sync application commands to. { error } " )
215-
216- else :
217- logger .error (f"Error syncing application commands: { error } " )
218-
219243 @reload_cog .error
220244 async def reload_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
221245 if isinstance (error , commands .MissingRequiredArgument ):
@@ -226,31 +250,6 @@ async def reload_error(self, ctx: commands.Context[commands.Bot], error: Excepti
226250 await ctx .send (f"Error reloading cog: { error } " )
227251 logger .error (f"Error reloading cog: { error } " )
228252
229- @unload_cog .error
230- async def unload_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
231- if isinstance (error , commands .MissingRequiredArgument ):
232- await ctx .send (f"Please specify an extension to unload. { error } " )
233- elif isinstance (error , commands .ExtensionNotLoaded ):
234- await ctx .send (f"That cog is not loaded. { error } " )
235- else :
236- logger .error (f"Error unloading cog: { error } " )
237-
238- @load_cog .error
239- async def load_error (self , ctx : commands .Context [commands .Bot ], error : Exception ) -> None :
240- if isinstance (error , commands .MissingRequiredArgument ):
241- await ctx .send (f"Please specify an cog to load. { error } " )
242- elif isinstance (error , commands .ExtensionAlreadyLoaded ):
243- await ctx .send (f"The specified cog is already loaded. { error } " )
244- elif isinstance (error , commands .ExtensionNotFound ):
245- await ctx .send (f"The specified cog is not found. { error } " )
246- elif isinstance (error , commands .ExtensionFailed ):
247- await ctx .send (f"Failed to load cog: { error } " )
248- elif isinstance (error , commands .NoEntryPointError ):
249- await ctx .send (f"The specified cog does not have a setup function. { error } " )
250- else :
251- await ctx .send (f"Failed to load cog: { error } " )
252- logger .error (f"Failed to load cog: { error } " )
253-
254253
255254async def setup (bot : commands .Bot ) -> None :
256255 await bot .add_cog (Dev (bot ))
0 commit comments