Answer the question
In order to leave comments, you need to log in
How to randomly open photos in Telegram Bot in Python?
Help with randomizing photos in Python in Telegram bot)
I have a bot project that, when you click on any inline button, should open pictures (depending on the number of photos in the folder).
If a person clicks on the Moscow button, then randomly the bot must select a folder in the Moscow folder (yes, there are folders in the Moscow folder in which photos are stored) and send it to the user, otherwise the folder stores a txt file with text that must be written together
Answer the question
In order to leave comments, you need to log in
You have folders (Moscow, St. Petersburg, Kazan, etc.) In each of them there are still folders (let's say there is a Kremlin folder in Moscow). This Kremlin folder has txt and pictures.
Let the user press the "Moscow" button. There are 3 folders: the Kremlin, Embankment, Sparrow Hills. Next, we get a list of all subfolders of the Moscow folder and randomly select any. We get its name, go into it and get all the photos (you can name 1.jpg, 2.jpg, etc., or get a list of all files with certain extensions jpg, png, etc.), it is advisable to always name the txt file the same (let's say desc.txt).
And we send the whole thing to the user.
Scary task "How to randomly open photos in Telegram Bot in Python?" results in several small subtasks,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question