S
S
Spoon in the brain2019-05-06 21:16:29
Python
Spoon in the brain, 2019-05-06 21:16:29

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

2 answer(s)
E
enabl3, 2019-05-07
@enabl3

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)

S
sound901, 2019-05-06
@saund901

Should we guess ourselves? Read the docs, google
https://github.com/eternnoir/pyTelegramBotAPI/blob...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question