V
V
ViktorFilatov2022-01-25 17:38:06
Python
ViktorFilatov, 2022-01-25 17:38:06

How to read text from message PyTelegramBotApi?

Hello! Started studying the PyTelegramBotApi library. There was a problem: I receive the text in a variable not the one I am going to enter, but with which I call the timer function.

import telebot
from telebot import types
import time

token = ""

bot = telebot.TeleBot(token)

# content_types=['text'] - сработает, если нам прислали текстовое сообщение
@bot.message_handler(commands=['start'])
def start(message):
    user = message.chat.id
    bot.send_message(user, "HI, here is my new bot, that works like a timer.")
    bot.send_message(user, "Your main command here is - /todo")
@bot.message_handler(commands=['todo'])
def todo(message):
    user = message.chat.id
    bot.send_message(user, "Now there are only two functions:")
    bot.send_message(user, "Timer for once time - /timer")
    bot.send_message(user, "Timer for a few times - /ltimer")

@bot.message_handler(commands=['timer'])
def timer(message):
    user = message.chat.id
    bot.send_message(user, "Write here what u need to be reminded of")
    text1 = message.text
    remind = message.text
    bot.send_message(user, remind)

if __name__ == '__main__':
    bot.infinity_polling()

Specifically, in the timer function, I display the text that I was going to enter, and it turned out to be a function call. Help fix this.
61f00add7d81b568565419.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Evseev, 2022-01-25
@ViktorFilatov

You need register_next_step_handler(). With it, when /timer is called, the bot will wait for the next message. An example can be found here https://github.com/eternnoir/pyTelegramBotAPI/blob...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question