F
F
FloppaPelmeni2022-02-05 22:25:00
Python
FloppaPelmeni, 2022-02-05 22:25:00

How to send a random photo via telebot?

I need the bot to send a random photo from a variable, how can I do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
lnerim, 2022-02-06
@FloppaPelmeni

path_list = ["image1.png", "image2.png", "image3.png"]  # Это имена файлов в папке с ботом

def callback_worker(call):
    if call.data == "rand":
        random_path = random.choice(path_list)
        with open(random_path, "rb") as file:
            bot.send_photo(call.message.chat.id, file.read())

Try this, should work. Otherwise, I agree with the commentators.

K
kokapuk, 2022-02-05
@kokapuk

random.choice

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question