Telebot API after separation, handlers don't work
When assembling the code in a single file, everything works. I think there is a mistake in importing or launching the bot.
import asyncio
from telebot.async_telebot import AsyncTeleBot
from src.config import Config
from src.keyboards import goods_keyboard
bot = AsyncTeleBot(token=Config.token)
@bot.message_handler(commands=['start'])
async def send_welcome(message):
kb = goods_keyboard({"Заказать товар": 'categories', "Корзина": 'cart', "Настройки": 'settings'})
await bot.send_message(message.chat.id, "Добро пожаловать на Вкусную Ферму!", reply_markup=kb)
async def main():
await bot.polling()
if __name__ == "__main__":
try:
asyncio.run(main())
except (KeyboardInterrupt, SystemExit):
print("Bot stopped!")
In this case command 'start' will work. But other code from files 'categories.py' or 'callbacks.py' didn't work...
from src.bot import bot
from src.keyboards import goods_keyboard
@bot.message_handler(commands=['categories'])
async def send_categories(message):
kb_text = {'Мясо': 'https://www.youtube.com/', 'Мясная продукция': 'https://www.youtube.com/',
'Назад': 'back'}
kb = goods_keyboard(kb_text)
await bot.send_message(message.chat.id, "Выберите категорию", reply_markup=kb)