So, from this image, you can see that this won't update the value of "wins" or "losses" despite the wins += 1
and losses += 1
addition I have under each if
/elif
statement.
Here is the code:
## Rock paper scissors
@bot.command(name="rps", description="Play rock paper scissors against the bot!", pass_context=True)
@commands.cooldown(1, 10, commands.BucketType.user)
async def rps(ctx):
em1 = discord.Embed(title="Rock Paper Scissors", description="What do you pick?", color=discord.Color.blue())
msg = await ctx.send(embed=em1)
rock = "🪨"
paper = "🧻"
scissors = "✂️"
options = ["🪨", "🧻", "✂️"]
await msg.add_reaction(rock)
await msg.add_reaction(paper)
await msg.add_reaction(scissors)
def check(reaction, user):
return user == ctx.author and str(reaction.emoji) in options
reaction, user = await bot.wait_for('reaction_add', timeout=60.0, check=check)
random_number = random.randint(0,2)
computer_pick = options[random_number]
wins = 0
losses = 0
desc = "Wins: " + str(wins) + "\n" + "Losses: " + str(losses)
emtie = discord.Embed(title="It's a tie!", description=desc, color=discord.Color.teal())
emlose = discord.Embed(title="You lost!", description=desc, color=discord.Color.red())
emwin = discord.Embed(title="You win!", description=desc, color=discord.Color.green())
if str(reaction.emoji) == rock and computer_pick == options[0]:
await ctx.send("You picked: " + rock + "\n" + "Computer picked: " + rock)
await ctx.send(embed=emtie)
elif str(reaction.emoji) == rock and computer_pick == options[1]:
losses += 1
await ctx.send("You picked: " + rock + "\n" + "Computer picked: " + paper)
await ctx.send(embed=emlose)
elif str(reaction.emoji) == rock and computer_pick == options[2]:
wins += 1
await ctx.send("You picked: " + rock + "\n" + "Computer picked: " + scissors)
await ctx.send(embed=emwin)
elif str(reaction.emoji) == paper and computer_pick == options[0]:
wins += 1
await ctx.send("You picked: " + paper + "\n" + "Computer picked: " + rock)
await ctx.send(embed=emwin)
elif str(reaction.emoji) == paper and computer_pick == options[1]:
await ctx.send("You picked: " + paper + "\n" + "Computer picked: " + paper)
await ctx.send(embed=emtie)
elif str(reaction.emoji) == paper and computer_pick == options[2]:
losses += 1
await ctx.send("You picked: " + paper + "\n" + "Computer picked: " + scissors)
await ctx.send(embed=emlose)
elif str(reaction.emoji) == scissors and computer_pick == options[0]:
losses += 1
await ctx.send("You picked: " + scissors + "\n" + "Computer picked: " + rock)
await ctx.send(embed=emlose)
elif str(reaction.emoji) == scissors and computer_pick == options[1]:
wins += 1
await ctx.send("You picked: " + scissors + "\n" + "Computer picked: " + paper)
await ctx.send(embed=emwin)
elif str(reaction.emoji) == scissors and computer_pick == options[2]:
await ctx.send("You picked: " + scissors + "\n" + "Computer picked: " + scissors)
await ctx.send(embed=emtie)
I feel like it may have to do with defining the desc = "Wins: " + str(wins) + "\n" + "Losses: " + str(losses)
right after the initial wins = 0
& losses = 0
, but I wouldn't know how else to arrange it in order for the embeds to work properly. I also feel like there may be an easy fix that I'm just not seeing, but if I'm not seeing it, hopefully someone else will.
You need to create your embed after the winner is decided. I suggest creating the embed in each of the if statements checking who won. Or you could just redefine the embed in the if statements. You could also have a function for creating the embed though that is up to you. Hope this helps :D.