Skip to content
How do I randomize responses?
Profile icon

Is there a way to give a bot a short list in the code so it can generate out one of a few responses? If someone types in p.h, the bot could respond with hi, hello, or hey. I've so far only seen tutorials that use APIs for random generation, but I don't need anything like that.

You are viewing a single comment. View All
Profile icon

You can import a random and make a list.

Roles = ["Imposter", "Crewmate", "Crewmate", "Crewmate", "Crewmate", "Imposter", "Crewmate", "Crewmate", "Crewmate", "Crewmate"]

Then you can make the random. It can be stored in a variable for future use of the same random.

Roles = random.choice(Roles)



The make the code do anything you want.

if Role == ("Imposter"): print("Imposter") print(Name) print(random.choice(Character)) elif Role == ("Crewmate"): print("Crewmate") print("There are two imposters among us.")

Hope that helps!