nickoala/telepot

How to send random jpg pictures from a folder?

Retul15 opened this issue · 1 comments

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.

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)