G
G
GRPUI2020-09-01 20:25:53
Python
GRPUI, 2020-09-01 20:25:53

When using a bot in a chat, it saves the chat id instead of the user id, how to change the code?

I'll miss the start

knownUsers = []


@bot.message_handler(commands=['start'])
def send_welcome(message):
    cid = message.chat.id
    if cid not in knownUsers:
        knownUsers.append(cid)
        userStep[cid] = 0
        bot.send_message(cid, "Привет " + str(message.from_user.first_name) + ' , приятно познакомиться')
        bot.send_message(cid, "Сканирование прошло успешно ")
        print(knownUsers)
        return cid
    else:
        bot.send_message(cid, "Ещё раз привет, " + str(message.from_user.first_name))
        return cid


When the /[email protected] command is entered in a chat by a user, his id should be checked and added to the knownUsers list. However, the chat id is added instead of the user id. And the "else" condition is constantly displayed, even if the user enters the command for the first time. I almost forgot, I use the telebot library.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2020-09-01
@GRPUI

message.chat.id - chat id
message.from_user.id - user id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question