R
R
Rukopashka2020-05-04 06:42:29
Python
Rukopashka, 2020-05-04 06:42:29

How to make new message assignment from telegram bot in python?

The variable "s" must store a variable of type str, example 15:58, then it is converted into an array [15, 58]. after the "Display Notification" request, the variable s takes that message instead of the next message. This is a test bot, on which I test new features for the main bot. Help me please. I have already climbed everywhere on the sites, I tried everything, but it does not work

spoiler
import telebot
import datetime
from telebot import apihelper
import time

bot = telebot.TeleBot("1099338538:AAE4m6rR1ALipNa63FXeRNhpq**********")

hello_text = "Hello!!!"
integ = []
hour_today = []
minut_today = []
today = datetime.datetime.today()
hour_today.append(today.hour)
minut_today.append(today.minute)


@bot.message_handler(commands=['start'])
def fisrt_message(message):
    bot.send_message(message.chat.id, hello_text)

@bot.message_handler(content_types=['text'])
def handle_message(message):
    if (message.text == 'Вывести уведомление'):
        bot.send_message(message.chat.id, "Пример: 14:00")
        s = message.text
        bot.send_message(message.chat.id, s)
        l = len(s)
        i = 0
        while i < l:
            s1 = ''
            a = s[i]
        while '0' <= a <= '9':
            s1 += a
            i += 1
            if i < l:
                a = s[i]
            else:
                break
        i += 1
        if s1 != '':
            integ.append(int(s1))
        bot.send_message(message.chat.id, integ)

bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikolay, 2020-05-04
@SODINNER

"variable s takes this message, not the next message"
If you need to store both the message earlier and receive subsequent data from the user, create a function like first_message (WITHOUT DECORATOR), and after getting the time 15:58, redirect to register_next_step_handler(new_function, message), thereby passing the same message, at least it is necessary to receive message.chat.id, but if you want to filter the message at the previous stage:
You do a check, and then if the check passed: you redirect to the next function, otherwise you write what you did wrong. I also recommend making one more additional parameter in the new function, where you will pass the time already converted to the list so that you do not have to convert it already in the new function, so the code will look cleaner.
Good luck =)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question