Answer the question
In order to leave comments, you need to log in
Sending a photo on command in telegram bot?
Evening at home!
I’m creating my first telegram bot and I wanted to generally throw a photo when sending a command /art
, I googled for a long time, but everyone throws only through the url, and I want to send photos by uploading from the computer, how to implement this, maybe there will be examples?
Answer the question
In order to leave comments, you need to log in
So you can send a random photo from your computer.
import random
import os
#send_random_picture
all_files_in_directory = os.listdir('path')
file = random.choice(all_files_in_directory)
doc = open('path' + '/' + file, 'rb')
#если нужно подпись к фото
caption = "любой текст"
#send_random_photo
bot.send_photo(chat_id, doc, caption)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question