提问人:maior _pain 提问时间:11/10/2023 最后编辑:maior _pain 更新时间:11/10/2023 访问量:57
为什么我的 if 语句不起作用?我在 discord.py 工作 [已关闭]
Why is my if statement not working? i working in discord.py [closed]
问:
我确信我做的一切都是正确的,在调试器的帮助下,我检查了条件,这是真的,但我仍然无法进一步。如果只是不起作用并且没有错误。所有其他代码都运行良好。
spisok_ownerow = ['1166775417210937400', '1166775635591569430', '1166777377821577247', '1167003611142819860', '1170749831975813240']
@bot.command()
async def give_xp(ctx, *args):
for id in spisok_ownerow:
roles = ctx.message.author.roles
for role in roles:
if role.id == id:
try:
haves = cursor.execute(f'SELECT have FROM players WHERE name=?', (args[0],))
conn.commit()
for haves in cursor.fetchall():
for have in haves:
cursor.execute('UPDATE players SET have = ? WHERE name = ?', (have+ int(args[1]), args[0]))
conn.commit()
await ctx.send(f'{args[0]} теперь имеет {have+ int(args[1])}xp')
sys.exit(1)
except Exception:
pass
else:
pass
答:
1赞
Cow
11/10/2023
#1
因此,根据评论中的故障排除,解决方案将是:
spisok_ownerow = ['1166775417210937400', '1166775635591569430', '1166777377821577247', '1167003611142819860', '1170749831975813240']
@bot.command()
async def give_xp(ctx, *args):
for id in spisok_ownerow:
roles = ctx.message.author.roles
for role in roles:
if role.id == int(id):
try:
haves = cursor.execute(f'SELECT have FROM players WHERE name=?', (args[0],))
conn.commit()
for haves in cursor.fetchall():
for have in haves:
cursor.execute('UPDATE players SET have = ? WHERE name = ?', (have+ int(args[1]), args[0]))
conn.commit()
await ctx.send(f'{args[0]} теперь имеет {have+ int(args[1])}xp')
sys.exit(1)
except Exception:
pass
else:
pass
评论
0赞
Jeyekomon
11/10/2023
没有子句的语句是这个问题的核心。“如果条件不满足,什么都不会发生”过去曾多次咬过我。if
else
评论
except Exception: pass
spisok_ownerow