'Problems in telegram bot commands

I'm creating a bot that sends math problems in image format. I wanted to create two two functions for different commands, so that one command only sends one genre of question, while the other sends another genre. Example: /random sends general problems, while /comb sends combinatorial problems.

My attempt:

@dp.message_handler(commands=['random', 'comb'])
async def random_cat(message: types.Message):
    captions = ["Nice problem!", "Niceeeeee :eyes:",
                "Noice", "Very cool"]
    caption = random.choice(captions)
    asyncio.create_task(fetch_cat())
    if dp.message_handler(commands=['random']):
        for image in [random.choice(["quest1.jpg", "quest2.jpg", "quest4.jpg", "quest5.jpg", "quest6.jpg",
                                    "quest7.jpg", "quest8.jpg","quest9.jpg", "quest10.jpg", "quest11.jpg", "quest12.jpg"])]:
            f = open(image, 'rb')
            photo = f.read()
            f.close()        
    elif dp.message_handler(commands=['comb']):
        for item in [random.choice(["quest14.jpg", "quest15.jpg"])]:
            r = open(item, 'rb')
            photo = r.read()
            r.close()             
    # _id = random.random()
    await bot.send_photo(chat_id=message.chat.id,
                         photo=photo,
                         caption=emojize(
                             caption) if caption == captions[1] else caption,
                         reply_to_message_id=message.message_id)
if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=True)

Even with the code, the bot sends the same messages for the same command. How to solve this? If possible, how can I change the codes to be able to put new commands for other types of questions in the future?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source