A
A
Alexander2018-02-16 11:33:19
Python
Alexander, 2018-02-16 11:33:19

How to properly read new group members?

I made a bot in the group so that it greets new people. I use telebot.
I have this code:

spoiler
@bot.message_handler(content_types=["new_chat_members"])
def handler_new_member(message):
    user_name = message.from_user.first_name
    bot.send_message(message.chat.id, "Добро пожаловать, {0}!".format(user_name))

When a person enters the chat, the bot, as expected, greets him using his name ( message.from_user.first_name ). It looks something like this:
5a8695d82f8e0896007267.png
But when someone invites people, the bot greets the one who invited . It looks like this: 5a8696a339b26477210045.png
Question: how to make the bot write the name of the invitee in the second case , and not the inviter?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2018-02-17
@AlexNineteen

@bot.message_handler(content_types=["new_chat_members"])
def handler_new_member(message):
    user_name = message.new_chat_member.first_name
    bot.send_message(message.chat.id, "Добро пожаловать, {0}!".format(user_name))

J
Jordan_Belforts, 2020-09-08
@Jordan_Belforts

@dp.message_handler(content_types=["new_chat_members"])
async def handler_new_member(message):
    first_name = message.new_chat_members[0].first_name

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question