fix: исправил crash в on_command_error при текстовых командах

- ctx.command.name: добавлена проверка ctx.command на None
- ctx.interaction: добавлен hasattr() — атрибута нет у commands.Context
  (текстовые команды !prefix), что вызывало AttributeError
This commit is contained in:
deadzilla 2026-06-09 18:19:18 +05:00
parent 978340f0dd
commit d698380cd7

7
bot.py
View File

@ -51,13 +51,16 @@ async def on_command_error(ctx, error):
return return
# Терминал — детали для разработчика # Терминал — детали для разработчика
cmd_name = ctx.command.name if ctx and ctx.command else '?'
logger.error( logger.error(
f"Ошибка команды {ctx.command.name if ctx else '?'}: {error}", f"Ошибка команды {cmd_name}: {error}",
exc_info=True, exc_info=True,
) )
# Discord — только если команда не ответила сама # Discord — только если команда не ответила сама
if ctx and ctx.interaction and ctx.interaction.response.is_done(): # ctx.interaction есть только у slash-команд (AutoshardedInteractionContext)
# Для текстовых команд (!prefix) атрибута нет — используем hasattr
if ctx and hasattr(ctx, 'interaction') and ctx.interaction and ctx.interaction.response.is_done():
return return
try: try: