Обработка сообщения зависимости от выбранной команды и текста, бот

@bot.message_handler(commands=['Weather'])
def city(message):
bot.send_message(message.chat.id, 'Enter city')
if message.chat.type == 'private':
    owm = OWM('API KEY')
    mgr = owm.weather_manager()
    observation = mgr.weather_at_place(message.text)
    w = observation.weather
    status = w.detailed_status
    temperature = w.temperature('celsius')['temp']
    cits = message.text
    bot.send_message(message.chat.id,
                        f'In the {cits} now {status} \n Temperature = {temperature} degrees Celsius.')

введите сюда описание изображения


Ответы (1 шт):

Автор решения: Violet
from pyowm import OWM


@bot.message_handler(commands=['weather'])
def city(message):
    msg = bot.send_message(message.chat.id, 'Enter city')
    bot.register_next_step_handler(msg, city_2)


def city_2(message):
    if message.chat.type == 'private':
        owm = OWM('API KEY')
        mgr = owm.weather_manager()
        observation = mgr.weather_at_place(message.text)
        w = observation.weather
        bot.send_message(message.chat.id,
                         f'In the {message.text} now {w.detailed_status}\n'
                         f'Temperature = {w.temperature("celsius")["temp"]} degrees Celsius.')
→ Ссылка