Почему не работает Telegram бот python telebot?

Всем привет, нужна ваша помощь..(
написал бота, все 83 строчки правильные но выдает ошибку
Чего только не делал, и хэндлеры менял и функции добавлял всегда одна и таже ошибка которая ещё и повторяется.

ВОТ КОД:

import telebot
from telebot import types

bot = telebot.TeleBot(':')

@bot.message_handler()
def start_markup():
    markup = types.InlineKeyboardMarkup(row_width=True)
    link_keyboard1 = types.InlineKeyboardButton(text="Канал со шмотками⚡️", url="https://t.me/izhcentralshop)
    link_keyboard2 = types.InlineKeyboardButton(text="название канала скрыто⚡️", (ссылка скрыта)")
    link_keyboard3 = types.InlineKeyboardButton(text="Канал с фильмами⚡️", url="https://t.me/claudfilms")
    check_keyboard = types.InlineKeyboardButton(text="Проверить подписку✅", callback_data="check")
    markup.add(link_keyboard1, link_keyboard2, link_keyboard3, check_keyboard)
    return markup


@bot.message_handler(commands=["start"])
def start(message):
    chat_id = message.chat.id
    first_name = message.chat.first_name
    bot.send_message(chat_id, f"Привет, {first_name}!\n"
                              f"Чтобы пользоваться ботом подпишитесь на каналы-спонсоры❗️❗️❗️",
                     reply_markup=start_markup())


def check(call):
    status = ['creator', 'administrator', 'member']
    for i in status:
        if i == bot.get_chat_member(chat_id="-1001889879299", user_id=call.message.chat.id).status:
            bot.send_message(call.message.chat.id, f"Спасибо, что подписались на каналы!\n"
                                                   f"Чтобы найти фильм введите его код в поле")
            break

        else:
            bot.send_message(call.message.chat.id, "Подпишитесь на наш канал!", reply_markup=start_markup())


@bot.callback_query_handler(func=lambda call: True)
def callback(call):
    if call.data == 'check':
        check(call)


@bot.message_handler(content_types=["int"])
def get_user_text(message):
    bot.send_message(message.chat.id, 'Введите код')

    if message.text == '2638':
        mesfrst = f'Отличный выбор, ваш фильм называется <b>«1+1»</b>'
        bot.send_message(message.chat.id, mesfrst, parse_mode='html')
        photo1 = open("photo1677832813.PNG", 'rb')
        bot.send_photo(message.chat.id, photo1)

    elif message.text == '1222':
        messcnd = f'Отличный выбор, ваш фильм называется <b>«Здравствуй папа новый год»</b>'
        bot.send_message(message.chat.id, messcnd, parse_mode='html')
        photo2 = open("photo1677832879.PNG", 'rb')
        bot.send_photo(message.chat.id, photo2)

    elif message.text == '3015':
        mesthrd = f'Отличный выбор, ваш фильм называется <b>«Стражи галактики»</b>'
        bot.send_message(message.chat.id, mesthrd, parse_mode='html')
        photo3 = open("photo1677832907.PNG", 'rb')
        bot.send_photo(message.chat.id, photo3)

    elif message.text == '3391':
        mesfrth = f'Отличный выбор, ваш фильм называется <b>«Изобретение лжи»</b>'
        bot.send_message(message.chat.id, mesfrth, parse_mode='html')
        photo4 = open("photo1677838354.PNG", 'rb')
        bot.send_photo(message.chat.id, photo4)

    elif message.text == '7535':
        mesffth = f'Отличный выбор, ваш фильм называется <b>«Крокодил Данди»</b>'
        bot.send_message(message.chat.id, mesffth, parse_mode='html')
        photo5 = open("photo1678024849.PNG", 'rb')
        bot.send_photo(message.chat.id, photo5)

    elif message.text == '4517':
        messxth = f'Отличный выбор, ваш фильм называется <b>«Улетный экзамен»</b>'
        bot.send_message(message.chat.id, messxth, parse_mode='html')
        photo6 = open("photo1678207276.PNG", 'rb')
        bot.send_photo(message.chat.id, photo6)

    elif message.text == '8777':
        messvnth = f'Отличный выбор, ваш фильм называется <b>«Рокки»</b>'
        bot.send_message(message.chat.id, messvnth, parse_mode='html')
        photo7 = open("photo1678277182.PNG", 'rb')
        bot.send_photo(message.chat.id, photo7)

    elif message.text == '4841':
        meseighth = f'Отличный выбор, ваш фильм называется <b>«Шеф Адам Джонс»</b>'
        bot.send_message(message.chat.id, meseighth, parse_mode='html')
        photo8 = open("photo1678277343.PNG", 'rb')
        bot.send_photo(message.chat.id, photo8)

    else:
        bot.send_message(message.chat.id, "К сожалению я не знаю такого кода(((")


bot.polling(none_stop=True)


__________________________________________________________________________________________________________________________________

ВОТ ОШИБКА:

2023-03-10 00:10:12,292 (__init__.py:960 MainThread) ERROR - TeleBot: "Infinity polling exception: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized"
2023-03-10 00:10:12,295 (__init__.py:962 MainThread) ERROR - TeleBot: "Exception traceback:
Traceback (most recent call last):
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\__init__.py", line 955, in infinity_polling
    self.polling(non_stop=True, timeout=timeout, long_polling_timeout=long_polling_timeout,
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\__init__.py", line 1040, in polling
    logger.info('Starting your bot with username: [@%s]', self.user.username)
                                                          ^^^^^^^^^
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\__init__.py", line 273, in user
    self._user = self.get_me()
                 ^^^^^^^^^^^^^
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\__init__.py", line 1236, in get_me
    result = apihelper.get_me(self.token)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\apihelper.py", line 196, in get_me
    return _make_request(token, method_url)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\apihelper.py", line 162, in _make_request
    json_result = _check_result(method_name, result)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\lyapi\PycharmProjects\pythonProject5\venv\forCannaFLMs\Lib\site-packages\telebot\apihelper.py", line 189, in _check_result
    raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized
"
  • Вопрос задан
  • 1000 просмотров
Пригласить эксперта
Ответы на вопрос 2
TalismanChet
@TalismanChet
Лицо зла
1. проверь, что токен правильный.
2. лучше храни токен в отдельном файле как константу и импортируй его в основной скрипт.
3. почитай док-ю по pyTelegramBotApi, может найдешь полезную иформацию (если п.1 не помог).

и ещё, зачем ставить флаг none_stop? поллинг и так infinity, так что, может проблема в этом, но это ОЧЕНЬ маловероятно (скорее всего он не влияет на аутенфикацию бота, а действует только на обертку telebot).
Ответ написан
Комментировать
toxa82
@toxa82
023-03-10 00:10:12,292 (__init__.py:960 MainThread) ERROR - TeleBot: "Infinity polling exception: A request to the Telegram API was unsuccessful. Error code: 401. Description: Unauthorized"
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы