Answer the question
In order to leave comments, you need to log in
How to make a variable in a bot global for only one person?
Hello! Faced the following problem:
I am making a telegram bot that leaves comments on the site.
Using this code:
def desc(message):
username = message.from_user.username
idd = message.from_user.id
msg = message.text
c.execute("INSERT INTO ads (worker,wid,title) VALUES (%s,%s,%s)",(username,idd,msg))
link.commit()
c.execute("SELECT id FROM ads WHERE worker = %s AND wid = %s AND title = %s",(username,idd,msg))
global ad_id
ad_id = c.fetchall()[0]['id'];
msg = bot.send_message(message.chat.id,"Коментарий:")
bot.register_next_step_handler(msg,price)
def price(message):
username = message.from_user.username
idd = message.from_user.id
msg = message.text
c.execute("UPDATE ads SET description = %s WHERE id = %s",(msg,ad_id))
link.commit()
msg = bot.send_message(message.chat.id,"Теперь цена с копейками (Пример: 7000.00)")
bot.register_next_step_handler(msg,comision)
def comision(message):
username = message.from_user.username
idd = message.from_user.id
msg = message.text
c.execute("UPDATE ads SET price = %s WHERE id = %s",(msg,ad_id))
link.commit()
msg = bot.send_message(message.chat.id,"На последок комиссию укажи (Пример: 70.00)")
bot.register_next_step_handler(msg,succes)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question