-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_bot_2.py
33 lines (26 loc) · 1.12 KB
/
test_bot_2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from aiogram import Bot, Dispatcher
from aiogram.filters import CommandStart
from aiogram.types import KeyboardButton, Message
from aiogram.utils.keyboard import ReplyKeyboardBuilder
BOT_TOKEN = 'YOUR_TOKEN'
bot = Bot(token=BOT_TOKEN)
dp = Dispatcher()
# Инициализируем билдер
kb_builder = ReplyKeyboardBuilder()
# Создаем список с кнопками
buttons: list[KeyboardButton] = [
KeyboardButton(text=f'Кнопка {i + 1}') for i in range(10)
]
# Распаковываем список с кнопками в билдер, указываем, что
# в одном ряду должно быть 4 кнопки.
kb_builder.row(*buttons, width=4)
# Этот хэндлер будет срабатывать на команду /start
# и отправляет в чат клавиатуру.
@dp.message(CommandStart())
async def process_start_command(message: Message):
await message.answer(
text='Вот такая получается клавиатура',
reply_markup=kb_builder.as_markup(resize_keyboard=True)
)
if __name__ == '__main__':
dp.run_polling(bot)