【问题标题】:How to fix syntax error on the 'e' of 'else:' in python - discord.py如何修复python中'else:'的'e'上的语法错误 - discord.py
【发布时间】:2021-06-14 03:03:32
【问题描述】:

我不知道为什么会发生这种情况,我已经检查了一切,一切似乎都正常。这是代码(错误大约一半,我在括号旁边放了一些箭头。我不确定这是缩进问题还是什么。在此之前,“with open(”上方有一个错误) mainbank.json', 'w') as f" 位。

@client.command(name='fight_01')
@commands.cooldown(1, 30, commands.BucketType.user)
async def fight_goblin(ctx):
  rng1 = random.randint(1,3)
  rng2 = random.randint(1,3)
  if rng1 == int('2'):
    await ctx.channel.send("You searched all around and couldn't find a goblin, try again next time :(")


  else:
    await ctx.channel.send('You encountered a wild goblin!')
    goblin_hp = int('5')
    time.sleep(1.5)
    rng3 = random.randint(1, 10)
    if rng3 == int('3') or int('4') or int('7'):
      user = ctx.author
      users = await get_bank_data()
      await ctx.channel.send('The goblin got the first hit and you lost 1hp')
      users[str(user.id)]['hp'] -= int('1') 
      dmg = users[str(user.id)]['max_damage']
      rng4 = random.randint(0, dmg) 
      rng5 = str(rng4)
      content1 = 'You did ' + rng5 + ' damage'
      goblin_hp2 = goblin_hp - int(rng5)
      with open("mainbank.json",'w') as f:
       json.dump(users,f)
      users = await get_bank_data()
      if users[str(user.id)]['hp'] <= 0:
        await ctx.channel.send('You died, better luck next time')
      await ctx.channel.send(content1)
      
      
      if goblin_hp2 < int('1'):
        await ctx.channel.send('You killed the goblin')
        users[str(user.id)['bank'] + random.randint(20, 100)  

      
      (HERE IS THE PROBELM >>>>>)else:
        content2 = 'The goblin now has ' + str(goblin_hp2) + ' health left'
        await ctx.channel.send(content2)
        rng3 = random.randint(1, 10)
        if rng3 == int('3') or int('4') or int('7'):
        user = ctx.author
        users = await get_bank_data()
        await ctx.channel.send('The goblin hit you so you lost 1hp')
        users[str(user.id)]['hp'] -= int('1') 
        dmg = users[str(user.id)]['max_damage']
        rng4 = random.randint(0, dmg) 
        rng5 = str(rng4)
        content1 = 'You did ' + rng5 + ' damage'
        goblin_hp2 = goblin_hp - int(rng5)
        with open("mainbank.json",'w') as f:
          json.dump(users,f)
        users = await get_bank_data()
        if users[str(user.id)]['hp'] <= 0:
          await ctx.channel.send('You died, better luck next time')
        if goblin_hp2 < int('1'):
          await ctx.channel.send('You killed the goblin')
          users[str(user.id)['bank'] += random.randint(20, 100)  
          with open("mainbank.json",'w') as f:
            json.dump(users,f)

【问题讨论】:

    标签: python syntax syntax-error discord.py


    【解决方案1】:

    你的问题是之前的那一行

    users[str(user.id)['bank'] + random.randint(20, 100)  
    

    缺少结束]

    users[str(user.id)]['bank'] + random.randint(20, 100)  
                      ^
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-29
      • 2019-09-01
      • 1970-01-01
      相关资源
      最近更新 更多