• Find an incredible deal for Black Friday or Cyber Monday? Share those epic bargains with the community by posting them in this forum thread!

Question Discord random choice keeps choosing same person

salm2s

Commendable
Jul 21, 2017
236
4
1,715
6
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
 

Newtonius

Upstanding
Sep 25, 2019
498
94
340
39
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
 

ASK THE COMMUNITY

TRENDING THREADS