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 1
1
import copy
2
2
import logging
3
+ import re
3
4
import typing
4
5
from contextlib import suppress
5
6
from inspect import getdoc , iscoroutinefunction
@@ -410,9 +411,28 @@ async def sync_all_commands(
410
411
self .logger .debug (
411
412
f"Detected changes on { scope if scope is not None else 'global' } , updating them"
412
413
)
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
416
436
else :
417
437
self .logger .debug (
418
438
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