No module named telegram

** Help me with my code, I can’t find the error. More precisely, to eliminate it, with which diamonds I just didn’t dance, and it doesn’t rain.:**

Repl link:

my_bot
Fail 1

from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import (
    Updater,
    CommandHandler,
    MessageHandler,
    Filters,
    CallbackContext,
    CallbackQueryHandler,
)

# Инициализация бота и API-ключа
updater = Updater(
    token="<censored>", use_context=True
)


# Обработчик команды /start
def start(update: Update, context: CallbackContext) -> None:
    keyboard = [
        [
            InlineKeyboardButton("💅 Маникюр", callback_data="manicure"),
            InlineKeyboardButton("💆 Массаж", callback_data="massage"),
            InlineKeyboardButton("✂️ Стрижка", callback_data="haircut"),
        ]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text("Выберите услугу:", reply_markup=reply_markup)


# Обработчик нажатий на кнопки
def button(update: Update, context: CallbackContext) -> None:
    query = update.callback_query
    query.answer()

    if query.data in ["manicure", "massage", "haircut"]:
        query.edit_message_text(text=f"Вы выбрали: {query.data}")
        context.user_data["selected_service"] = query.data

        # Добавляем кнопку для поделиться геолокацией
        keyboard = [
            [
                InlineKeyboardButton(
                    "Поделиться геолокацией", callback_data="share_location"
                )
            ]
        ]
        reply_markup = InlineKeyboardMarkup(keyboard)
        query.message.reply_text("Выберите действие:", reply_markup=reply_markup)
    elif query.data == "share_location":
        query.message.reply_text(
            "Поделитесь своей геолокацией, нажав на кнопку под этим сообщением."
        )
        context.user_data["waiting_for_location"] = True


# Обработчик геолокации
def location(update: Update, context: CallbackContext) -> None:
    if context.user_data.get("waiting_for_location"):
        location = update.message.location
        update.message.reply_text("Спасибо за предоставленную геолокацию!")

        # Отправляем анимацию поиска
        context.bot.send_animation(
            chat_id=update.effective_chat.id,
            animation="https://example.com/search_animation.gif",
        )

        # Здесь вызывайте функцию для поиска мастеров и обработки данных

        context.user_data["waiting_for_location"] = (
            False  # Сбрасываем ожидание геолокации
        )
    else:
        update.message.reply_text(
            "Пожалуйста, воспользуйтесь кнопками для выбора услуги."
        )


# Регистрация обработчиков
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CallbackQueryHandler(button))
dispatcher.add_handler(MessageHandler(Filters.location, location))

# Запуск бота
updater.start_polling()

Fail2

from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
from telegram.ext import (
    Updater,
    CommandHandler,
    MessageHandler,
    Filters,
    CallbackContext,
    CallbackQueryHandler,
)

# Инициализация бота и API-ключа
updater = Updater(
    token="6153977111:AAF_Hw4L2x0MnCiC_H4wv1PZrTdFeYq6jQc", use_context=True
)


# Обработчик команды /start
def start(update: Update, context: CallbackContext) -> None:
    keyboard = [
        [
            InlineKeyboardButton("💅 Маникюр", callback_data="manicure"),
            InlineKeyboardButton("💆 Массаж", callback_data="massage"),
            InlineKeyboardButton("✂️ Стрижка", callback_data="haircut"),
        ]
    ]
    reply_markup = InlineKeyboardMarkup(keyboard)
    update.message.reply_text("Выберите услугу:", reply_markup=reply_markup)


# Обработчик нажатий на кнопки
def button(update: Update, context: CallbackContext) -> None:
    query = update.callback_query
    query.answer()

    if query.data in ["manicure", "massage", "haircut"]:
        query.edit_message_text(text=f"Вы выбрали: {query.data}")
        context.user_data["selected_service"] = query.data

        # Добавляем кнопку для поделиться геолокацией
        keyboard = [
            [
                InlineKeyboardButton(
                    "Поделиться геолокацией", callback_data="share_location"
                )
            ]
        ]
        reply_markup = InlineKeyboardMarkup(keyboard)
        query.message.reply_text("Выберите действие:", reply_markup=reply_markup)
    elif query.data == "share_location":
        query.message.reply_text(
            "Поделитесь своей геолокацией, нажав на кнопку под этим сообщением."
        )
        context.user_data["waiting_for_location"] = True


# Обработчик геолокации
def location(update: Update, context: CallbackContext) -> None:
    if context.user_data.get("waiting_for_location"):
        location = update.message.location
        update.message.reply_text("Спасибо за предоставленную геолокацию!")

        # Отправляем анимацию поиска
        context.bot.send_animation(
            chat_id=update.effective_chat.id,
            animation="https://example.com/search_animation.gif",
        )

        # Здесь вызывайте функцию для поиска мастеров и обработки данных

        context.user_data["waiting_for_location"] = (
            False  # Сбрасываем ожидание геолокации
        )
    else:
        update.message.reply_text(
            "Пожалуйста, воспользуйтесь кнопками для выбора услуги."
        )


# Регистрация обработчиков
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", start))
dispatcher.add_handler(CallbackQueryHandler(button))
dispatcher.add_handler(MessageHandler(Filters.location, location))

# Запуск бота
updater.start_polling()

Hi @Tyrexcom , welcome to the forums!
You can try entering pip install telegram into the Shell, which will install the telegram module.
Hope this helps!

1 Like