Search code examples
python-3.xtelethon

Catching telegram system message about user enter/leave chat


I have a small telegram group, where my bot has admin rights. I want to send greetings to new users (and post some goodbye, when user leaves chat). In pytgbotAPI you can catch system messages by this handler, so bot can send its reply:

@bot.message_handler(content_types=['left_chat_member', 'new_chat_members'])

In telethon handler that catches all users messages don't get telegram system messages about user entering and leaving chat:

@bot.on(events.NewMessage(incoming=True))

Is there any chance to handle this messages?


Solution

  • Found the solution:

    from telethon import events
    
    @client.on(events.ChatAction)
    async def handler(event):
        # Welcome every new user
        if event.user_joined:
            await event.reply('Welcome!')