Answer the question
In order to leave comments, you need to log in
How to send a file (photo/gif/video) from a folder in python chronological order?
Hello. I made it so that when you click on the button, the bot sends a random photo to the person. How can I make them send in chronological order, and when they end, they start again?
@bot.message_handler(content_types=['text'])
def event(message):
if message.chat.type == "private":
if message.text == "Случайный арт":
photo = open('Картиночки/' + random.choice(os.listdir('Картиночки')), 'rb')
bot.send_photo(message.chat.id, photo)
Answer the question
In order to leave comments, you need to log in
For each person, it is necessary to save the last sent picture to the database, and check the database with each subsequent sending.
to send "in chronological order" use os.stat to get the file's creation time. sort by it. well, save the last photo sent in some database so that next time you can send the next one
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question