File tree Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Expand file tree Collapse file tree 1 file changed +23
-3
lines changed Original file line number Diff line number Diff line change 11import copy
22import logging
3+ import re
34import typing
45from contextlib import suppress
56from inspect import getdoc , iscoroutinefunction
@@ -410,9 +411,28 @@ async def sync_all_commands(
410411 self .logger .debug (
411412 f"Detected changes on { scope if scope is not None else 'global' } , updating them"
412413 )
413- existing_cmds = await self .req .put_slash_commands (
414- slash_commands = to_send , guild_id = scope
415- )
414+ try :
415+ existing_cmds = await self .req .put_slash_commands (
416+ slash_commands = to_send , guild_id = scope
417+ )
418+ except discord .HTTPException as ex :
419+ if ex .status == 400 :
420+ # catch bad requests
421+ cmd_nums = set (
422+ re .findall (r"In\s(\d)." , ex .args [0 ])
423+ ) # find all discords references to commands
424+ error_string = ex .args [0 ]
425+
426+ for num in cmd_nums :
427+ error_command = to_send [int (num )]
428+ error_string = error_string .replace (
429+ f"In { num } " ,
430+ f"'{ error_command .get ('name' )} '" ,
431+ )
432+
433+ ex .args = (error_string ,)
434+
435+ raise ex
416436 else :
417437 self .logger .debug (
418438 f"Detected no changes on { scope if scope is not None else 'global' } , skipping"
You can’t perform that action at this time.
0 commit comments