Random file selection doesn't work (Discord.py)

Question:

I’m using Github so no OS here.

I’m trying to make it so you can write the command /mila and it will get you a random photo from my Github repository.

import random

@bot.command()
async def mila(ctx):
        Images = ["photo_2022-09-29_16-56-28.jpg", "photo_2022-09-29_16-56-31.jpg", "photo_2022-09-29_16-56-33.jpg", "photo_2022-09-29_16-56-35.jpg", "photo_2022-09-29_16-56-37.jpg", "photo_2022-09-29_16-56-38.jpg", "photo_2022-09-29_16-56-41.jpg", "photo_2022-09-29_16-56-42.jpg", "photo_2022-09-29_16-56-45.jpg", "photo_2022-09-29_16-56-47.jpg"]

        await ctx.send(random.choice(file=Discord.File(Images)))
Asked By: duckgcs

||

Answers:

This should work,

import random

@bot.command()
async def mila(ctx):
        Images = ["photo_2022-09-29_16-56-28.jpg", "photo_2022-09-29_16-56-31.jpg", "photo_2022-09-29_16-56-33.jpg", "photo_2022-09-29_16-56-35.jpg", "photo_2022-09-29_16-56-37.jpg", "photo_2022-09-29_16-56-38.jpg", "photo_2022-09-29_16-56-41.jpg", "photo_2022-09-29_16-56-42.jpg", "photo_2022-09-29_16-56-45.jpg", "photo_2022-09-29_16-56-47.jpg"]
        
        random_file = random.choice(Images)
        await ctx.send(file=Discord.File(random_file))
Answered By: Conner Wolf 08
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.