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

Telebot, How do I save a message from user into a variable?

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

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

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

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

@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

您可以将 "userPrice" 变量保存在数据库或 json/txt 文件中,这样变量就安全了。