Идентификатор канала Telegram я получил с помощью IDBot, что упростило процесс идентификации. Кроме того, я повысил статус бота до администратора на канале, предоставив ему полные административные привилегии.
import telebot
from helper import TextHelper
import os
import contants
import time
bot = telebot.TeleBot(contants.BOT_ACCESS_TOKEN, parse_mode=None)
obj = TextHelper()
@bot.message_handler(commands=['test'])
def send_ans(message):
try:
text = message.text.split(' ')[1]
stat, filex, captionx = obj.getText(text)
if stat == True:
bot.send_document(message.chat.id, open(filex, 'rb'), caption=captionx, reply_to_message_id=message.message_id)
os.remove(filex)
else:
bot.reply_to(message, captionx)
except Exception as e:
bot.reply_to(message, str(e))
def polling_wrapper():
while True:
try:
bot.remove_webhook()
bot.infinity_polling()
except Exception as e:
print(f"An error occurred: {e}")
time.sleep(5)
try:
polling_wrapper()
except KeyboardInterrupt:
pass
except Exception as e:
print(f"An unexpected error occurred: {e}")






мы можем использовать @bot.channel_post_handler()
который будет слушать сообщения канала и отвечать