I need my telegram bot to be able to send multiple photos in one message, but I can’t find this feature in the telebot library.
import telebot
TOKEN = "************"
CHANNEL_ID = "*****"
users_list = [*****]
def check_user_in_list(user_id):
if user_id in users_list:
return True
else:
return False
bot = telebot.TeleBot(TOKEN)
# Sending a message
def send_to_channel(message, file_id=None):
if file_id:
bot.send_photo(CHANNEL_ID, file_id, caption=message)
else:
bot.send_message(CHANNEL_ID, message)
# Message handler from the user
@bot.message_handler(content_types=['text'])
def handle_message(message):
user_id = message.from_user.id
if check_user_in_list(user_id):
send_to_channel(f"{message.text}")
@bot.message_handler(content_types=['photo'])
def handle_photo(message):
user_id = message.from_user.id
if check_user_in_list(user_id):
photo = message.photo[-1]
file_id = photo.file_id
bot.send_photo(CHANNEL_ID, file_id, caption=message.caption)
@bot.message_handler(content_types=['video'])
def handle_video(message):
user_id = message.from_user.id
if check_user_in_list(user_id):
video = message.video
file_id = video.file_id
bot.send_video(CHANNEL_ID, file_id, caption=message.caption)
bot.polling()
I tried to find a solution to my problem on the Internet, but I didn’t find anything
New contributor
delorine is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.