I use pyTelegramBotAPI. How to assign a message to a variable? Those. How to get the text of the message that the user sends to the bot?

  • text = message.text - Pavel Durmanov pm

1 answer 1

It is necessary to implement the function of “trapping” text-type messages in this way:

 @bot.message_handler(content_types=['text']) def handle_message(message): string = message.text 

The message class, which is a custom message, has a text field that stores the text of the message. This is the field we will assign to the variable.