Practica2025/bot/management/commands/runbot.py
2025-12-29 04:26:49 +03:00

28 lines
1016 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# bot/management/commands/runbot.py
from django.core.management.base import BaseCommand
from django.conf import settings
from telegram.ext import ApplicationBuilder, CommandHandler, CallbackQueryHandler
from bot.handlers import start, router
import logging
class Command(BaseCommand):
help = 'Запускает Telegram бота'
def handle(self, *args, **options):
# Логирование для отладки
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO
)
print("Starting bot...")
application = ApplicationBuilder().token(settings.TELEGRAM_TOKEN).build()
# Регистрация хендлеров
application.add_handler(CommandHandler("start", start))
# Все callback-и идут в наш роутер
application.add_handler(CallbackQueryHandler(router.handle))
application.run_polling()