Добрый день товарищи программисты. Первый раз работаю с api Telegram. Суть работы бота в том, что нужно пользователю подписаться на канал, и бот продолжает работу после того как проверит что он является подписчиком на канале. На просторах интернета нашёл только один способ. Это использование метода getChatMember для получения статуса пользователя. Проблема в том что при запросе Telegram отвечает на него ошибкой. Проблема точно не в библиотеке telebot, так как при обычном get запросе через браузер, ошибка та же. Видимо какая-то особенность api Telegram, которую я никак не могу понять. В общем вот код: Код | import telebot import config from telebot import types bot = telebot.TeleBot(config.TOKEN) @bot.message_handler(commands=['start']) def welcome(message): # Keyboard button_hi = types.KeyboardButton("СТАРТ") start_kb = types.ReplyKeyboardMarkup(resize_keyboard=True) start_kb.add(button_hi) bot.send_message(message.chat.id, "Описание работы бота\nИтак нажмите кнопку <b>«СТАРТ»</b> и следуйте инструкциям!".format(message.from_user, bot.get_me()), parse_mode='html', reply_markup=start_kb) @bot.message_handler(content_types=['text']) def lalala(message): button_next = types.KeyboardButton("ПРОДОЛЖИТЬ") next_kb = types.ReplyKeyboardMarkup(resize_keyboard=True) next_kb.add(button_next) if message.chat.type == 'private': if message.text == "СТАРТ": bot.send_message(message.chat.id, "✉️ Подпишитесь на 1-ый из 5-ти каналов - @idmanik", reply_markup=next_kb) elif message.text == 'ПРОДОЛЖИТЬ': button_next2 = types.KeyboardButton("К 2-МУ КАНАЛУ") next_kb2 = types.ReplyKeyboardMarkup(resize_keyboard=True) next_kb2.add(button_next2) status = ['creator', 'administrator', 'member'] for chri in status: if chri == bot.get_chat_member(chat_id="@idmanik", user_id=message.from_user.id).status: bot.send_message(message.chat.id, "Подписка подтверждена!") break else: bot.send_message(message.chat.id, "Кажется вы не подписались!") else: bot.send_message(message.chat.id, "Я не знаю что ответить") # RUN bot.polling(none_stop=True)
|
На выходе получаю ошибку при обращении к строке: 34 Код | [Running] python -u "c:\Users\tumen\OneDrive\Документы\GitHub\TelegramBOT\bot_to_sem.py" 2020-03-17 21:23:13,043 (util.py:66 WorkerThread2) ERROR - TeleBot: "ApiException occurred, args=('A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body:\n[b\'{"ok":false,"error_code":400,"description":"Bad Request: user not found"}\']',) Traceback (most recent call last): File "C:\Users\tumen\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\util.py", line 60, in run task(*args, **kwargs) File "c:\Users\tumen\OneDrive\Документы\GitHub\TelegramBOT\bot_to_sem.py", line 35, in lalala if chri == bot.get_chat_member(chat_id="@idmanik", user_id=message.from_user.id).status: File "C:\Users\tumen\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\__init__.py", line 579, in get_chat_member result = apihelper.get_chat_member(self.token, chat_id, user_id) File "C:\Users\tumen\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 246, in get_chat_member return _make_request(token, method_url, params=payload) File "C:\Users\tumen\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 60, in _make_request return _check_result(method_name, result)['result'] File "C:\Users\tumen\AppData\Local\Programs\Python\Python38-32\lib\site-packages\telebot\apihelper.py", line 79, in _check_result raise ApiException(msg, method_name, result) telebot.apihelper.ApiException: A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: user not found"}'] " 2020-03-17 21:23:13,043 (__init__.py:420 MainThread) ERROR - TeleBot: "A request to the Telegram API was unsuccessful. The server returned HTTP 400 Bad Request. Response body: [b'{"ok":false,"error_code":400,"description":"Bad Request: user not found"}']"
|
В случае работы через браузер с помощью прямого запроса ответ тот же. Видимо это особенность апи. Но какая?
|