Z
Z
zenondd2020-09-07 10:51:05
Python
zenondd, 2020-09-07 10:51:05

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)


Can you please tell me what method can be used so that the bot can calculate the sum of the given values?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
terentjew-alexey, 2020-09-07
@terentjew-alexey

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 question

Ask a Question

731 491 924 answers to any question