Telebot,如何将用户的消息保存到变量中?

1 python python-telegram-bot telegram-bot

我正在制作一个电报机器人,它会询问用户不同的问题,我需要将他们的答案保存到变量中。

@bot.message_handler(commands=['addproduct'])
def handle_text(message):
    bot.send_message(message.chat.id, "Price =")
Run Code Online (Sandbox Code Playgroud)

然后用户回答,程序应该将答案保存到可变价格中。

如何将用户的消息保存到变量中?

Bat*_*ico 5

@bot.message_handler(commands=['addproduct'])
def handle_text(message):
    cid = message.chat.id
    msgPrice = bot.send_message(cid, 'Set your price:')
    bot.register_next_step_handler(msgPrice , step_Set_Price)

def step_Set_Price(message):
    cid = message.chat.id
    userPrice= message.text
Run Code Online (Sandbox Code Playgroud)

您可以将“userPrice”变量保存在数据库或json/txt 文件中,然后您就有了变量安全。