Skip to content

Commit 906e61e

Browse files
Make sync_all_commands errors easier to understand (#253)
Co-authored-by: Ben Woo <30431861+benwoo1110@users.noreply.github.com>
1 parent d68ea8e commit 906e61e

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

discord_slash/client.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import copy
22
import logging
3+
import re
34
import typing
45
from contextlib import suppress
56
from 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"

0 commit comments

Comments
 (0)