How to manage more users in a telegram bot?

5.7k views Asked by At

I did a telegram bot with python, who send a message like

if message == '/start':
    bot.sendMessage(chat_id, "Insert your name:")
    a = 'name'
if a == 'name' and message != '/start'
    name_user = message
    bot.sendMessage(chat_id, "Insert your birthday:")
    a = 'birth'
    and so on for other information...

the problem came when at the same time two users use my bot because the first user change 'a' so the second start with the birth and not with the name, can someone help me please?

3

There are 3 answers

0
Sean Wei On BEST ANSWER

Store with user ID.

a[chat_id] = name
0
Majeed Askari On

You need to use a database for that purpose. have a field called State with a primary field of user's ChatID. after each response from your users check the state of that user from db.

Sean's answer is also correct but this way you will lose your users states if your program restarts for some reason.

0
Abdul Gandal On

You should to consider a database, create it using sqlite3. Into the database create a table which corrisponds to each user (eg. table: db(str(chat.id))). And into each table create columns where you could put the information of your users (including also chat.id).