A
A
Anim8262020-11-02 16:37:42
Bots
Anim826, 2020-11-02 16:37:42

I get an error in aiogram, what should I do?

I decided to learn how to write tg bots on the library, and I had to add inline buttons, and I seem to have done it, but after that I changed something and kaput, the bot does not start, but in the console it gives out this

python bot.py
Updates were skipped successfully.
Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at C:\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py:380> exception=AttributeError("'Message' object has no attribute 'send_message'")>
Traceback (most recent call last):
  File "C:\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:\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 225, in process_updates
    return await asyncio.gather(*tasks)
  File "C:\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "C:\Python38\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 246, in process_update
    return await self.message_handlers.notify(update.message)
  File "C:\Python38\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "bot.py", line 16, in main
    await message.send_message(message.from_user.id, 'Главное меню', reply_markup=kb.inline_kb1)
AttributeError: 'Message' object has no attribute 'send_message'


After writing python bot.py, it starts up and works, but as soon as I write the start in the bot, the error shown above comes out, I assume that somewhere I entered something wrong or didn’t import anything.

The code itself is all:
bot.py
import keyboards as kb
from config import *
from aiogram import Bot, Dispatcher, executor, types
from aiogram.types import Message
from aiogram.dispatcher.filters import Command


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


@dp.message_handler(commands=['start'])
async def main(message: types.Message):
  await message.send_message(message.from_user.id, 'Главное меню', reply_markup=kb.inline_kb1)

@dp.callback_query_handler(text='Info')
async def info(call: types.CallbackQuery):
  await call.answer(cache_time=60)

  await call.message.answer('text', reply_markup=kb.inline_kb_back)

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


config.py
BOT_TOKEN = 'токен'
ADMIN_ID = 'мой айди'


keyboards.py
from aiogram.types import ReplyKeyboardRemove, \
    ReplyKeyboardMarkup, KeyboardButton, \
    InlineKeyboardMarkup, InlineKeyboardButton


buttonInfo = InlineKeyboardButton(' Информация о колледже ', callback_data='Info')
buttonPostuplenie = InlineKeyboardButton('‍ Поступление ‍', callback_data='Postuplenie')
buttonAnketa = InlineKeyboardButton(' Вступительная анкета ', callback_data='Anketa')
buttonVopros = InlineKeyboardButton('❔ Частые вопросы ❔', callback_data='Vopros')
buttonContacti = InlineKeyboardButton(' Контакты ', callback_data='Contacti')
buttonDocument = InlineKeyboardButton(' подача документов ', callback_data='Document')

inline_kb1 = InlineKeyboardMarkup().row(buttonInfo).row(buttonPostuplenie).row(buttonAnketa).row(buttonDocument).row(buttonVopros).row(buttonContacti)

buttonBack = InlineKeyboardButton(' В главное меню', callback_data='back')

inline_kb_back = InlineKeyboardMarkup().row(buttonBack)


Ps No, I did not take on a real project, it's just practice and study of the aiogram library

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-11-02
@Anim826

It's obvious that it should be
bot.send_message

C
Cat Frisky, 2022-01-22
@cat_frisky

you can also use the answer
message.answer('some text', reply_markup=kb.inline_kb_back) method

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question