简体   繁体   English

如何修复 python - discord.py 中 'else:' 的 'e' 上的语法错误

[英]How to fix syntax error on the 'e' of 'else:' in python - discord.py

I have no idea why this is happening, I have checked everything and all seems working.我不知道为什么会这样,我检查了一切,一切似乎都正常。 Here is the code( the error is about halfway down, I put some arrows next to it in brackets. I'm not sure if it's an indent issue or what. Before this there was an error just above on the "with open('mainbank.json', 'w') as f" bit.这是代码(错误大约一半,我在括号旁边放了一些箭头。我不确定这是缩进问题还是什么。在此之前,“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)

your problem is the line before你的问题是前行

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

is missing a closing ]缺少一个结束]

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM