AIOGram. How to fix chat_member_handler?

Viewed 349

I need my bot to do specific things when an user is joining end exiting a group. First, I write proof-of-concept code:

@dp.chat_member_handler()
async def user_joined_chat(update: types.ChatMemberUpdated):
    print('Users changed')

But that does nothing. I added-deleted the test user to the test group many times, but nothing. Of course, I have made sure "privacy mode" is disabled and the bot is an administrator of the group before.

What's wrong? Do I use wrong handler?

1 Answers

You have to use other handler, handler that you are trying to use handles ChatMember status changes. You have to use classic message_handler and handle content types like: NEW_CHAT_MEMBERS and LEFT_CHAT_MEMBER you can find such types here so there is working code:

@dp.message_handler(content_types=[types.ContentType.NEW_CHAT_MEMBERS, types.ContentType.LEFT_CHAT_MEMBER])
async def user_joined_chat(message: types.Message):
    print('Users changed')
Related