如何修复 python - discord.py 中 'else:' 的 'e' 的语法错误
How to fix syntax error on the 'e' of 'else:' in python - discord.py
我不知道为什么会这样,我检查了一切,一切似乎都正常。这是代码(错误大约是一半,我在它旁边的括号中放了一些箭头。我不确定这是缩进问题还是什么。在此之前,“with open('mainbank.json', 'w') 作为 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)
你的问题是前一行
users[str(user.id)['bank'] + random.randint(20, 100)
缺少结尾 ]
users[str(user.id)]['bank'] + random.randint(20, 100)
^
我不知道为什么会这样,我检查了一切,一切似乎都正常。这是代码(错误大约是一半,我在它旁边的括号中放了一些箭头。我不确定这是缩进问题还是什么。在此之前,“with open('mainbank.json', 'w') 作为 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)
你的问题是前一行
users[str(user.id)['bank'] + random.randint(20, 100)
缺少结尾 ]
users[str(user.id)]['bank'] + random.randint(20, 100)
^