r/pythonhelp • u/[deleted] • May 11 '21
how to create randomness
Hello. I made a discord bot using python and i figured out how to use it to send files. My issue is, i have alot of images and i want to make it so that one command works for multiple images but it cycles through them ramdomly. Regular random or shuffle commands do not work for this. the command to send a file is:
@ client.command()
async def example(ctx):
await ctx.send(file=dsc.File('example.txt'))
the installer is:
pip install discord
and to import it do:
import discord as dsc
If anyone has any idea how i can do this that would be very helpfull!
0
Upvotes
1
u/MrPhungx May 12 '21
You can scan your directory and search for all files that have the ending '.png' for example. Save all these paths to a list. Then you can select one of those image paths with random.choice(path_list)