'How to make the bot send a random photo to aiogram?

I need to force the telegram bot on aiogram to send a random photo to the chat, how can I do this. Thanks in advance for your reply



Solution 1:[1]

You can send photo from your files. You also can send photo by file_id, the principle is the same:

    # import aiogram and random
    @dp.message_handler(commands=["photo"])
    async def sendphoto(msg):
        arr=["image1path", "image2path", ...] # or imagefileid
        photo=open(random.choice(arr), "rb")
        await bot.send_photo(msg.from_user.id, photo)
    

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 Black Hat