K
K
Kiryan Kiryan2021-06-06 08:58:25
Python
Kiryan Kiryan, 2021-06-06 08:58:25

I wanted to add buttons to my bot but they are not displayed. What could be the problem?

Wanted to add buttons to my bot using aiogram. It seems that everything was imported and there are no errors in the code, but for some reason the buttons are not displayed. The bot code is below.

from config import TOKEN, bot_token
from aiogram import Bot, types
from aiogram.dispatcher import Dispatcher
from aiogram.utils import executor


bot = Bot(token=bot_token)
dp = Dispatcher(bot)


@dp.message_handler(commands=["start"])
async def start_command(message: types.Message):
    keyboard = types.ReplyKeyboardMarkUp()
    btn1 = types.KeyboardButton(text="Moscow")
    keyboard.add(btn1)
    await message.reply("Напиши название своего города", reply_markup = keyboard)

@dp.message_handler()
async def get_weather(message: types.Message):
    code_smile = {
        "Clear": "Ясно ",
        "Clouds": "Облачно ☁",
        "Rain": "Дождь ",
        "Thunderstorm": "Гроза ⛈",
        "Snow": "Снег ",
        "Mist": "Туман "
    }

    try:
        r = requests.get(
            f"http://api.openweathermap.org/data/2.5/weather?q={message.text}&appid={TOKEN}&units=metric"
        )
        data = r.json()

        city = data["name"]
        cur_weather = data["main"]["temp"]

        weather_description = data["weather"][0]["main"]
        if weather_description in code_smile:
            wd = code_smile[weather_description]
        else:
            wd = "Посмотри в окно, я хз чо там)"

        humidity = data["main"]["humidity"]
        pressure = data["main"]["pressure"]
        wind = data["wind"]["speed"]
        sunrise_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunrise"])
        sunset_timestamp = datetime.datetime.fromtimestamp(data["sys"]["sunset"])
        length_of_the_day = datetime.datetime.fromtimestamp(data["sys"]["sunset"]) - datetime.datetime.fromtimestamp(
            data["sys"]["sunrise"])

        await message.reply(f"***{datetime.datetime.now().strftime('%Y-%m-%d %H:%M')}***\n"
              f"Погода в городе: {city}\nТемпература: {cur_weather}{wd}\n"
              f"Влажность: {humidity}%\nДавление: {pressure} мм.рт.ст\nВетер: {wind} м/с\n"
              f"Восход: {sunrise_timestamp}\nЗакат: {sunset_timestamp}\nПродолжительность дня: {length_of_the_day}\n"
              f"Хорошего дня!"
              )

    except:
        await message.reply("  Чел, Проверь название города  ")


if __name__ == '__main__':
    executor.start_polling(dp)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-06-06
@kiryan2

There is no such type ReplyKeyboardMarkUp, he ReplyKeyboardMarkup.
There should be errors in the console about this

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question