import telebot
from telebot import types
bot = telebot.TeleBot("2326723433:AAGPmMBtTykQtVVZ_xC8BCbD0F-9-8OKXh4")
def start_markup():
markup = types.InlineKeyboardMarkup(row_width=1) # row_width должен быть целым числом
link_keyboard1 = types.InlineKeyboardButton(text="1 канал", url="https://t.me/kzvrkt")
link_keyboard2 = types.InlineKeyboardButton(text="2 канал", url="https://t.me/kzvrkd")
check_keyboard = types.InlineKeyboardButton(text="Проверить", callback_data="check")
markup.add(link_keyboard1, link_keyboard2, 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}", reply_markup=start_markup())
def check(call, chat_id):
try:
member = bot.get_chat_member(chat_id, user_id=call.from_user.id)
return member.status in ["creator", "administrator", "member"]
except telebot.apihelper.ApiTelegramException as e:
print(f"Error checking membership: {e}")
return False
def check_channels(call):
channel_ids = [-1002261050865, -1002293699737] # Используем целые числа без пробелов
if all(check(call, channel_id) for channel_id in channel_ids):
bot.send_message(call.message.chat.id, "Спасибо за подписку ✨")
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_channels(call)
if __name__ == "__main__":
bot.infinity_polling()
import telebot
from telebot import types
bot = telebot.TeleBot("2326723433:AAGPmMBtTykQtVVZ_xC8BCbD0F-9-8OKXh4")
def start_markup():
markup = types.InlineKeyboardMarkup(row_width=True)
link_keyboard1 = types.InlineKeyboardButton(text="1 канал", url=" https://t.me/kzvrkt ") #!
link_keyboard2 = types.InlineKeyboardButton(text="2 канал", url=" https://t.me/kzvrkd ") #?
check_keyboard = types.InlineKeyboardButton(text="Проверить", callback_data="check")
markup.add(link_keyboard1, link_keyboard2, 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}", reply_markup=start_markup())
def check(call, chat_id):
st = bot.get_chat_member(chat_id, user_id=call.message.chat.id).status
return st in ["creator", "administrator", "member"]
def check_channels(call):
if check(call, "-1002261050865") and check(call, " -1002293699737"):
bot.send_message(call.message.chat.id, "Спасибо за подписку ✨")
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_channels(call)
if __name__ == "__main__":
bot.polling(none_stop=True)
пишет raise ApiTelegramException(method_name, result, result_json)
telebot.apihelper.ApiTelegramException: A request to the Telegram API was unsuccessful. Error code: 400. Description: Bad Request: chat not found
"