@Warlam

Телеграм бот на aiogram выдает ошибку?

Каждый раз выдает одну и ту же ошибку после того, как дело доходит до функций kartoxa и grecha

Task exception was never retrieved
future: exception=TypeError("to_python() missing 1 required positional argument: 'self'")>
Traceback (most recent call last):
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 388, in _process_polling_updates
for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 225, in process_updates
return await asyncio.gather(*tasks)
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 246, in process_update
return await self.message_handlers.notify(update.message)
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "C:\Users\Даня\bot\main.py", line 33, in kartoxa
await msg.answer("Уважаю",reply_markup=ReplyKeyboardRemove),
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\types\message.py", line 339, in answer
return await self.bot.send_message(
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\bot\bot.py", line 312, in send_message
reply_markup = prepare_arg(reply_markup)
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\utils\payload.py", line 56, in prepare_arg
return json.dumps(_normalize(value))
File "C:\Users\Даня\AppData\Local\Programs\Python\Python38\lib\site-packages\aiogram\utils\payload.py", line 42, in _normalize
return obj.to_python()
TypeError: to_python() missing 1 required positional argument: 'self'

main.py:
import asyncio

from aiogram.types import ReplyKeyboardMarkup, KeyboardButton
from aiogram.types import ReplyKeyboardRemove
from aiogram import Bot, Dispatcher, executor, types
from config import BOT_TOKEN

loop = asyncio.get_event_loop()
bot = Bot(token=BOT_TOKEN,parse_mode="HTML")
dp = Dispatcher(bot,loop=loop)

menu=ReplyKeyboardMarkup(
keyboard=[
[KeyboardButton(text="картоха"),
KeyboardButton(text="гречка")],

],resize_keyboard=True)

@dp.message_handler(commands=['start'])
async def start(msg:types.message):
await msg.answer("Ку")

@dp.message_handler(commands=['menu'])
async def show_menu(msg:types.message):
await msg.answer("Выбирай",reply_markup=menu)

@dp.message_handler(text='картоха')
async def kartoxa(msg:types.message):
await msg.answer("Уважаю",reply_markup=ReplyKeyboardRemove),

@dp.message_handler(text='гречка')
async def grecha(msg: types.message):
await msg.answer("not bad",reply_markup=ReplyKeyboardRemove)

if __name__ == '__main__':
from handlers import dp,send_to_admin
executor.start_polling(dp,on_startup=send_to_admin)

config.py:
BOT_TOKEN = "токен(он есть)" # Забираем значение типа str
ADMINS = # Тут у нас будет список из админов

handlers.py:
from main import bot, dp
from config import ADMINS
from aiogram.types import Message

async def send_to_admin(dp):
await bot.send_message(chat_id=ADMINS,text="Бот запущен")

@dp.message_handler()
async def echo(message:Message):
text = f"{message.text}"
await message.answer(text=text)
  • Вопрос задан
  • 1853 просмотра
Решения вопроса 1
sergey-gornostaev
@sergey-gornostaev Куратор тега Python
Седой и строгий
Потому что в параметр reply_markup нужно передавать объект, а не класс.
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы