'Send random Images with Hikari Python

I'm new to coding and i would like to ask if anybody knows if it's possible to send (random) images from folder with hikari in python and can help me edit my code

@lightbulb.command('img', 'image')
@lightbulb.implements(lightbulb.PrefixCommand)
async def image(ctx):
    f = hikari.File('C:/Users/User/Desktop/folder/file.jpg')
    await ctx.respond(f)


Solution 1:[1]

This could work:

images = os.path.join(os.getcwd(), "images")
def select_random_image_path():
    return os.path.join(images, random.choice(os.listdir(images)))

@lightbulb.command('img', 'image')
@lightbulb.implements(lightbulb.PrefixCommand)
async def image(ctx):
    f = hikari.File(select_random_image_path())
    await ctx.respond(f)

If your file structure looks like below:

|   main.py
+---images
|       73doCML.jpg
|       BcAyMo7.jpg
|       eRcYeHL.jpg
|       HSlG1Gl.jpg
|       IDgfXn6.jpg
|       ljFuj1z.jpg
|       MmBXwZN.jpg
|       N0udyAV.jpg
|       xenAlf8.png
|       yc1kX4A.jpg
|       ZJubdTU.jpg

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