发出战斗指令,但生命值不减

问题描述

目标:我的目标是你提到一个用户并开始一场战斗,每 1 秒从你当前的生命值中减去 5 到 20 之间的随机数量。这种情况会一直持续到有人的生命值为 0 为止。

我的问题:在上层代码中,代码每秒发送一条消息,不减|在底部代码中,代码不会每秒发送一条消息,而是显示 (edited)。减法也不起作用

@client.command()
async def fight(ctx,user : discord.Member = None):
  turn1 = 100
  turn2 = 100
  beginner = ctx.author

  embedprogress=discord.Embed(title="⚔️fighting!",color=0x7289da,description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
  msg = await ctx.send(embed=embedprogress)

  while turn1 or turn2 > 0:
    turn1 - random.randint(5,20)
    turn2 - random.randint(5,20)
    await asyncio.sleep(1)
    await msg.edit(embed=embedprogress)
  else:
    embedover=discord.Embed(title="⚔️fight ended!",description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    await ctx.send(embed=embedover)
async def fight(ctx,description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
  msg = await ctx.send(embed=embedprogress)

  while turn1 or turn2 > 0:
    turn1 -= random.randint(5,20)
    turn2 -= random.randint(5,description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    await ctx.send(embed=embedover)

这两个代码的区别在于 turn1 - random.randint(5,20) 行中的等号。

解决方法

你定义了嵌入但是当健康改变时你没有更新它,我修复了一些其他错误,我可以告诉你没有太多的python经验我建议你在尝试之前学习这门语言使用它。这是固定代码:

@client.command()
async def fight(ctx,user : discord.Member = None):
    turn1 = 100
    turn2 = 100
    beginner = ctx.author

    embedprogress=discord.Embed(title="⚔️Fighting!",color=0x7289da,description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    msg = await ctx.send(embed=embedprogress)

    while True:
        turn1 -= random.randint(5,20)
        turn2 -= random.randint(5,20)
        embedprogress=discord.Embed(title="⚔️Fighting!",description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
        await asyncio.sleep(1)
        await msg.edit(embed=embedprogress)
        if turn1 < 0 or turn2 < 0:
            break

    embedover=discord.Embed(title="⚔️Fight ended!",description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    await msg.edit(embed=embedover)

附注:如果您需要更多帮助,请在不和谐中添加我:LUNA#6969,我很乐意为您提供帮助。