Skip to content

Cannot cast ChatMember to any subclass #623

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
MasterGroosha opened this issue Jul 8, 2021 · 0 comments · Fixed by #624
Closed

Cannot cast ChatMember to any subclass #623

MasterGroosha opened this issue Jul 8, 2021 · 0 comments · Fixed by #624
Labels
bug Something is wrong with the framework confirmed This issue is confirmed and requires action

Comments

@MasterGroosha
Copy link
Contributor

  • Operating System: Manjaro KDE Edition
  • Python Version: 3.9
  • aiogram version: 2.14.2

I tried to get type of ChatMember subclass (e.g. ChatMemberAdministrator, ChatMemberLeft etc.), however this code fails:

import asyncio
import logging
from aiogram import Bot, Dispatcher, types

bot = Bot(token="BOT_TOKEN")
dp = Dispatcher(bot)
logging.basicConfig(level=logging.INFO)

@dp.chat_member_handler()
async def chat_member_handler(update: types.ChatMemberUpdated):
    print(f"[{update.from_user.id}] {type(update.old_chat_member.resolve())} -> {type(update.new_chat_member.resolve())}")

async def main():
    await dp.start_polling(allowed_updates=types.AllowedUpdates.all())

asyncio.run(main())

Exception:

ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-8' coro=<Dispatcher._process_polling_updates() done, defined at %PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py:409> exception=ValueError("Can't find `ChatMember` class for status `None`")>
Traceback (most recent call last):
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 417, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 238, in process_updates
    return await asyncio.gather(*tasks)
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/dispatcher.py", line 309, in process_update
    return await self.chat_member_handlers.notify(update.chat_member)
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/dispatcher/handler.py", line 116, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "%PROJECTDIR%/bot.py", line 12, in chat_member_handler
    print(f"[{update.from_user.id}] {type(update.old_chat_member.resolve())} -> {type(update.new_chat_member.resolve())}")
  File "%PROJECTDIR%/venv/lib/python3.9/site-packages/aiogram/types/chat_member.py", line 80, in resolve
    raise ValueError(f"Can't find `ChatMember` class for status `{status}`")
ValueError: Can't find `ChatMember` class for status `None`

Steps to Reproduce

  1. Run the code above (don't forget to put your own token)
  2. Add bot to a group and make it admin
  3. Restrict any chat member (e.g. revoke any permission from them)
@Olegt0rr Olegt0rr added bug Something is wrong with the framework confirmed This issue is confirmed and requires action labels Jul 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is wrong with the framework confirmed This issue is confirmed and requires action
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants