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

Making a fight command, but health doesnt subsctract

目标: 我的目标是你提到一个用户,它开始一场战斗,每 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!", color=0x7289da, description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    await ctx.send(embed=embedover)
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!", color=0x7289da, 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!", color=0x7289da, 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!", color=0x7289da, description=f"{beginner.mention} ❤️ - {turn1}\n{user.mention} ❤️ - {turn2}")
    await msg.edit(embed=embedover)

旁注:如果您需要更多帮助,请在 discord 上加我:LUNA#6969 我很乐意为您提供帮助。