Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
2.1 kB
11
Indexable
Never
import asyncio
import logging
import sys
import time
from os import getenv

from aiogram import Bot, Dispatcher, Router, types
from aiogram.fsm import state
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import StatesGroup, State
from aiogram.methods.send_message import SendMessage
from aiogram.client import bot
from aiogram.enums import ParseMode
from aiogram.filters import CommandStart
from aiogram.types import Message, ReplyKeyboardMarkup, KeyboardButton
from aiogram.utils.markdown import hbold
from aiogram.methods.send_message import SendMessage



from aiogram import Bot, types


TOKEN = "1156:AAFJ"

dp = Dispatcher()


class SetWord(StatesGroup):
    word = State()


async def on_startup():
    print("Бот успешно запущен")

@dp.message(CommandStart())
async def command_start_handler(message: Message, state: FSMContext) -> None:
    await state.set_state(SetWord.word)
    print(message.from_user.id,message.from_user.full_name)

    await message.answer(f"Здравствуйте, {hbold(message.from_user.full_name)}!")
    await message.answer("Введите: Фамилию Имя Отчество ( через пробел без знаков припинания в формате ФИО")
    await message.delete()


    user_id = 1111111111
    message_text = "Привет, это сообщение отправлено без команды пользователя!"
    await bot.send_message(chat_id=user_id, text=message_text)



@dp.message(SetWord.word)
async def check_word(message: types.Message, state: FSMContext):
    await state.update_data(word=message.text)  # записываем в класс
    data = await state.get_data()  # достаем из класса
    print(data)
    await state.clear()  # очищаем класс


async def main() -> None:

    bot = Bot(TOKEN, parse_mode=ParseMode.HTML)
    await on_startup()
    await dp.start_polling(bot)




if __name__ == "__main__":
    # logging.basicConfig(level=logging.INFO, stream=sys.stdout)
    asyncio.run(main())
Leave a Comment