How to make python bot pick a random name. For example if I provide a list of answers.
answers = ["apple", "ball", "cat", "dog", "elephant", "frog", "gun"]
@bot.command()
async def choose(k : int):
"""Chooses between multiple choices."""
if 0 <= k <= 50:
await bot.say("This is your random {} pick".format(k))
embed = discord.Embed(description='\n'.join(random.choices(answers, k=k)))
await bot.say(embed=embed)
else:
await bot.say("Invalid number")
This Python function picks 5 random elements out of a given list.
It iterates 5 times and uses a randomly selected integer to pull an element from the given list, then removes it to avoid duplicates. It uses the random module to accomplish this.
I don't know about getting it to discord, but I think this is what you were looking for.
You can use
random.choices
(notchoice
) to selectn
items with replacement, if you are on Python 3.6+