Answer the question
In order to leave comments, you need to log in
What can 'Bot' object has no attribute 'message_handler' fix?
I am writing a bot, learning to work with a database. At the moment, the purpose of the code is this: The user enters a command, and the bot adds the id to the database.
# инициализируем бота
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)
# инициализируем соединение с БД
db = SQLighter('database.db')
@dp.message_handler(commands=['admins'])
async def subscribe(message: types.Message):
if(not db.subscriber_exists(message.from_user.id)):
# если юзера нет в базе, добавляем его
db.add_subscriber(message.from_user.id)
else:
# если он уже есть, то просто обновляем ему статус подписки
db.update_subscription(message.from_user.id, True)
await message.answer("Вы успешно добавлены в базу")
@bot.message_handler(commands=['start'])
def welcome(message):
. . .
Traceback (most recent call last):
File "bot.py", line 31, in <module>
@bot.message_handler(commands=['start'])
AttributeError: 'Bot' object has no attribute 'message_handler'
Answer the question
In order to leave comments, you need to log in
@dp.message_handler vs @bot.message_handler
would have learned in regular python, not async, otherwise you don’t even understand this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question