skip to Main Content

Can Telegram bot detect a new member joining a channel event?

I have a Telegram bot and I set this bot as admin of a channel. I need to get the user id who joined to the channel and send me a private message with user details. is this possible?

2

Answers


  1. I’m not familiar with the python implementation, but I can provide some information based on the official HTTP-based specification.

    In order to listen for a member joining a channel, you would listen for Updates of type chat_member. Each one will provide two values of ChatMember, one representing the user before s/he joined the chat and one for afterwards.

    At this point, the API is not clearly worded, unfortunately, but you can simply do some tests. I assume that if the member object for ‘before’ has status = "left", then this user just joined the chat.

    Login or Signup to reply.
  2. Yes, you can!

    Offical link: https://core.telegram.org/bots/api#chatmemberupdated

    import telebot
    from telebot.util import update_types
    
    bot = telebot.TeleBot("your bot token here")
    
    @bot.chat_member_handler()
    def memberUpdated1(updated):
        print('chat_member_handler -----> ', updated)
    
    bot.infinity_polling(allowed_updates=update_types)
    

    Note: You need add bot to your channel and set it to admin!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search