nickoala / telepot

Python framework for Telegram Bot API
MIT License
2.43k stars 478 forks source link

How to send random jpg pictures from a folder? #427

Open Retul15 opened 5 years ago

Retul15 commented 5 years ago

I have a folder of jpg pictures. I'm trying to make a Telegram bot where each time a user send roll, it will send a picture from the folder randomly.

tasi788 commented 5 years ago
import random
from glob import glob

#https://docs.python.org/3/library/glob.html
pic_list = glob('*.jpg')

get_random_pic = random.choice(pic_list)
with open(get_random_pic, 'rb') as photo:
   sendPhoto(chat_id, photo)