Skip to content

fix(chatbot): resolve channel sender AttributeError and fix empty repai command crash - #135

Open
FPSensor wants to merge 2 commits into
TeamUltroid:mainfrom
FPSensor:main
Open

fix(chatbot): resolve channel sender AttributeError and fix empty repai command crash#135
FPSensor wants to merge 2 commits into
TeamUltroid:mainfrom
FPSensor:main

Conversation

@FPSensor

@FPSensor FPSensor commented Aug 7, 2026

Copy link
Copy Markdown

Summary

This PR addresses two critical runtime errors in chatbot.py that cause event loop crashes and fill console logs with unnecessary exceptions.


🐛 Bug Fixes & Changes Made

1. Fix AttributeError on Channel Messages (chatBot_replies)

  • Issue: When a channel posts a message or comment (e.g., in discussion groups), Telethon returns a Channel entity as the sender rather than a User. Because Channel objects do not possess a .bot attribute, calling if sender.bot: raises AttributeError: 'Channel' object has no attribute 'bot'.
  • Fix: Safely check the attribute using getattr(sender, 'bot', False) and added a check to verify sender exists before evaluating.

2. Fix MessageIdInvalidError / IndexError on Empty .repai

  • Issue: Executing .repai without a reply target or additional text triggers an IndexError when attempting to split the command args. The subsequent except block attempted to edit the command message using eod(), which threw a telethon.errors.rpcerrorlist.MessageIdInvalidError in environments without edit permissions on the original message.
  • Fix: Replaced the eod() helper call with event.reply() in the exception handler to safely alert the user without raising RPC errors.

🧪 Testing

  • Tested .repai with no arguments, verified the user receives the missing args prompt via reply without crashing.
  • Simulated incoming channel messages in a group with chatBot_replies active; verified no AttributeError is logged.

…Bot_replies

Resolved an issue in the chatBot_replies event handler where messages sent by channels caused an AttributeError: 'Channel' object has no attribute 'bot'. Replaced the direct attribute access with getattr() to safely verify the sender's bot status without crashing the event loop.
…epai

Fixed a crash in the repai command when executed without arguments. The previous implementation raised an IndexError and subsequently caused a MessageIdInvalidError by attempting to edit the original message using eod in contexts lacking edit permissions. Replaced the error notification mechanism with a standard reply() to ensure safe execution.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant