Discord python 嵌入不会更新数值

Discord python embed won't update numerical value

因此,从这张图片中,您可以看到这不会更新“赢”或“输”的值,尽管我在每个 if/elif 语句。

代码如下:

## 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)

我觉得这可能与在初始 wins = 0 & losses = 0 之后定义 desc = "Wins: " + str(wins) + "\n" + "Losses: " + str(losses) 有关,但我不知道如何按顺序排列它使嵌入正常工作。我也觉得可能有一个简单的修复方法,只是我没有看到,但如果我没有看到,希望其他人会看到。

您需要在确定获胜者后创建您的嵌入。我建议在检查谁赢了的每个 if 语句中创建嵌入。或者您可以在 if 语句中重新定义嵌入。你也可以有一个创建嵌入的功能,尽管这取决于你。希望这有帮助 :D.