Question Discord random choice keeps choosing same person

salm2s

Honorable
Jul 21, 2017
266
6
10,815
Hi there,
So i made this test bot where when i input a command, it will randomly choose a person and mention them:
Code:
if message.content.startswith(prefix+("choose")):
    channel = message.channel
    response1 = random.choice(channel.guild.members).mention
    response2 = random.choice(channel.guild.members).mention
    response3 = random.choice(channel.guild.members).mention
    await message.channel.send(f'{response1}, {response2} and {response3} are the best')

The problem is that it keeps choosing the same person twice. Sometimes i get lucky and it chooses 3 different people, but it rarely happens.

How can i make it so that the bot does not choose the same person again?

Thanks,
salm2s
 
Try a loop underneath each response that's after response1 that checks if the user is the same as the previous responses.

For example:
response1 = random.choice(channel.guild.members).mention
response2 = random.choice(channel.guild.members).mention
while (response2 == response1) :
response2 = random.choice(channel.guild.members).mention