L
L
Liza_Lob2022-01-20 03:55:12
Python
Liza_Lob, 2022-01-20 03:55:12

How to properly set up a bot in python?

@bot.message_handler(
    content_types=['new_chat_member'])
def greeting(message):
    print("User " + message.new_chat_member.first_name + " added")
    try:
        bot.reply_to(message, text='Швыр вступил в группу',
                     disable_notification=True)
    except OSError:
        print("GreetingError - Sending again after 5 seconds!!!")
        time.sleep(3)
        bot.reply_to(message, text='Швыр вступил в группу',
                     disable_notification=True)


@bot.message_handler(
    content_types=['left_chat_member'])
def not_greeting(message):
    print("User " + message.left_chat_member.first_name + " left")
    try:
        bot.reply_to(message, text='Швыр покинул группу',
                     disable_notification=True)
    except OSError:
        print("LeftError - Sending again after 5 seconds!!!")
        time.sleep(3)
        bot.reply_to(message, text='Швыр покинул группу',
                     disable_notification=True)

When a person joins the group, the bot does not send anything, but when a person leaves the group, everything is sent properly, why is that?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vindicar, 2022-01-20
@Vindicar

A quick googling shows that the content_types for the user spawn might be new_chat_member s rather than new_chat_member. Check if it works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question