Вот код:
from aiogram import Bot, Dispatcher, types
from aiogram.utils import executor
from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher.filters.state import StatesGroup,State
from aiogram.dispatcher import FSMContext
bot = Bot('5520319617:AAFgd7Z68BejkIv2SZ9SfmXkjaa7WVKnWJk')
dp = Dispatcher(bot,storage=MemoryStorage())
TO_CHAT_ID = 965665251
storage = MemoryStorage()
class state_g(StatesGroup):
hi = State()
number = State()
priyom = State()
sdacha = State()
gruz = State()
time_pr = State()
accept = State()
cansel = State()
@dp.message_handler(commands='start')
async def start(message:types.Message):
global u_id, TO_CHAT_ID
u_id = message.from_user.id
await bot.send_message(u_id, f'Приветсвую вас {message.from_user.first_name} я бот который поможет'
f'вам отправить заявку на доставку нашей компанией ')
await bot.send_message(u_id, f'доставка любого груза будет стоить от 20 рублей оплата на месте')
await bot.send_message(u_id, f'Если вы со всем согласны то тогда давайте начнём заполнение бланка.Отправьте ваше ФИО')
await state_g.hi.set()
@dp.message_handler(state=state_g.hi)
async def hi1(message: types.Message, state: FSMContext):
global u_id
answer = message.text
await state.update_data(hi=answer)
await bot.send_message(u_id, f'хорошо теперь отправьте ваш номер телефона')
await state_g.number.set()
@dp.message_handler(state=state_g.number)
async def hi2(message: types.Message, state: FSMContext):
global u_id
answer = message.text
await state.update_data(number=answer)
await bot.send_message(u_id, f'хорошо теперь отправьте адрес с которого нужно забрать груз')
await state_g.priyom.set()
@dp.message_handler(state=state_g.priyom)
async def hi3(message: types.Message, state: FSMContext):
global u_id
answer = message.text
await state.update_data(priyom=answer)
await bot.send_message(u_id, f'хорошо теперь отправьте адрес на который нужно доставить груз')
await state_g.sdacha.set()
@dp.message_handler(state=state_g.sdacha)
async def hi4(message: types.Message, state: FSMContext):
global u_id
answer = message.text
await state.update_data(sdacha=answer)
await bot.send_message(u_id, f'хорошо теперь отправьте название самого груза')
await state_g.gruz.set()
@dp.message_handler(state=state_g.gruz)
async def hi5(message: types.Message, state: FSMContext):
global u_id
answer = message.text
await state.update_data(gruz=answer)
await bot.send_message(u_id, f'хорошо теперь отправьте время к которому нужно забрать груз')
await state_g.time_pr.set()
@dp.message_handler(state=state_g.time_pr)
async def hi6(message: types.Message, state: FSMContext):
global u_id
answer = await message.text
data = await state.get_data()
name = await data.get('hi')
number = await data.get('number')
priyom =await data.get('priyom')
sdacha = await data.get('sdacha')
gruz = await data.get('gruz')
time_pr = await data.get('time_pr')
print('работает')
await state.update_data(time_pr=answer)
await bot.send_message(u_id, f'ФИО:{name}\n'
f'номер телефона: {number}\n'
f'адрес приёма груза:{priyom}\n'
f'адрес сдачи груза:{sdacha}\n'
f'груз:{gruz}\n'
f'время приёма груза:{time_pr}\n'
f'всё верно?',reply_markup=u_kb)
await state.finish()
'''BUTTONS'''
button_gom = KeyboardButton('да')
button_otm = KeyboardButton('нет')
button_cansel = KeyboardButton('не принимать')
button_accept = KeyboardButton('принято')
u_kb = ReplyKeyboardMarkup(resize_keyboard=True).row(button_gom, button_otm)
# a_kb = ReplyKeyboardMarkup(resize_keyboard=True).row(button_cansel, button_accept)
if __name__ == '__main__':
print('бот запущен')
executor.start_polling(dp)
А вот ошибка:
Task exception was never retrieved
future: <Task finished name='Task-34' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=TypeError("object str can't be used in 'await' expression")>
Traceback (most recent call last):
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\User\Desktop\иван\telegramm_bots — копия\dost_bot\dost_bot_main.py", line 89, in hi6
answer = await message.text
TypeError: object str can't be used in 'await' expression
Task exception was never retrieved
future: <Task finished name='Task-37' coro=<Dispatcher._process_polling_updates() done, defined at C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=TypeError("object str can't be used in 'await' expression")>
Traceback (most recent call last):
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\User\Desktop\иван\venv\lib\site-packages\aiogram\dispatcher\handler.py", line 116, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\User\Desktop\иван\telegramm_bots — копия\dost_bot\dost_bot_main.py", line 89, in hi6
answer = await message.text
TypeError: object str can't be used in 'await' expression