B
B
bebraglov2022-04-18 11:30:30
Python
bebraglov, 2022-04-18 11:30:30

How to make the bot send a random photo?

Hello, I need to make a bot that will send a random photo when a person writes some text.

def init(update,context):
    if "как дела" in message.text.lower():
    directory = "/isxodniki"
    random_image = random.choice(os.listdir(directory))
    bot.send_photo(update.message.chat_id, photo=open(directory + random_image,'rb'))

It seems to have done everything right, but it does not work.
Help)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question