Answer the question
In order to leave comments, you need to log in
How to "teach" a bot to address its messages?
Good day everyone! I am now mastering Python, in particular, creating telegram bots in this language. I decided to write a bot for playing "21" and got stuck at the moment when the bot needs to calculate the sum of all previously "issued" values (cards). Here is an excerpt from my banal code:
if message.text == 'Начать':
blackgame = types.ReplyKeyboardMarkup(True, False)
blackgame.row('Еще...', 'Себе', 'Пас')
bot.send_message(message.chat.id, 'Ваша карта:')
bot.send_message(message.chat.id, random.choice(rand.Cards), reply_markup=blackgame)
Answer the question
In order to leave comments, you need to log in
The most elementary way:
Store the state of the session with the client in the script's memory. You start a dictionary, where as a key - the id of the client, and as a value, any data structure convenient for the task. Accordingly, no matter who sends the message to the bot, it always has an idea of what stage the game is at.
There is no way to read sent messages, you can only change the message sent by the bot (I could be wrong). And this, in principle, is an approach through writing crutches.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question