bybacapitan
bybacapitan

Reputation: 15

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

Upvotes: 0

Views: 6918

Answers (1)

odduck41
odduck41

Reputation: 76

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)
    

Upvotes: 2

Related Questions