P
P
PolDamian2019-06-16 18:25:11
Python
PolDamian, 2019-06-16 18:25:11

How to consistently receive messages in a Telegram bot?

@bot.message_handler(content_types=['text'])
def handle_messages(messages):
  for message in messages:

        if message.text == "/start":
            bot.send_message(
                message.chat.id,
                messages.start_message[0] + '\n' +  messages.start_message[1]
            )
            print(message.from_user.id)

        elif message.text.lower() == "/newplayer":
            new_player_name = message.from_user.first_name
            new_player_id = message.from_user.id
            player.new_player(new_player_name, new_player_id)
            bot.send_message(message.from_user.id, messages.player_created)
            print(player.qplayers)
        elif message.text == "/help":
            bot.send_message(message.from_user.id, "используй /start")
        elif message.text == "/startgame":
            bot.send_message(message.from_user.id,'Добро пожаловать в игру финансовые воротилы!')
            mes=1
            tabl.Level=3
            bot.send_message(message.from_user.id,'Начало игры')
            while mes < 13:
                bot.send_message(message.from_user.id,'Текущий месяц = ' + str(mes))
                costs.monthlyCosts()
                starshiy=m.fmod(mes, player.CurNumOfGamers)
                tabl.Level=tabl.LevelCount(tabl.Level) 
                Esm.AcquisitionOfEsm(tabl.Level, message, bot)
                production.productionEgp()
                Egp.AcquisitionOfEgp(tabl.Level)
                for ActualGamer in range(player.CurNumOfGamers):
                    buildings.buildings(ActualGamer)
                mes+=1
        else:
            bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")    
bot.polling(none_stop=True, interval = 5)

I am writing a telegram bot using Python and the telebot library. I need to call the function after reading the command, but in it I need to re-accept messages from the user and save them to the function variables. That is, after entering the / startgame command, when the Esm.AcquisitionOfEsm () function is launched, it is necessary to re-watch what the user enters from the keyboard. What code do I need to add to Esm.AcquisitionOfEsm()?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Bushmanov, 2019-06-18
@assanti

Store user state.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question