为什么我的 if 语句不起作用?我在 discord.py 工作 [已关闭]

Why is my if statement not working? i working in discord.py [closed]

提问人:maior _pain 提问时间:11/10/2023 最后编辑:maior _pain 更新时间:11/10/2023 访问量:57

问:


编辑问题以包括所需的行为、特定问题或错误以及重现问题所需的最短代码。这将有助于其他人回答这个问题。

14天前关闭。

我确信我做的一切都是正确的,在调试器的帮助下,我检查了条件,这是真的,但我仍然无法进一步。如果只是不起作用并且没有错误。所有其他代码都运行良好。

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
python if 语句

评论

3赞 khelwood 11/10/2023
也许会抛出一个例外,你完全躲在你的except Exception: pass
1赞 ewokx 11/10/2023
欢迎来到 Stack Overflow。你到底在期待什么?输入是什么?什么是 ?spisok_ownerow
1赞 buran 11/10/2023
如果只是不起作用并且没有错误,当然,当您在 try/except 块中捕获所有异常时不会出现错误
0赞 maior _pain 11/10/2023
我用调试器检查了一下,它甚至没有比 if 条件更进一步
0赞 buran 11/10/2023
这是什么意思,甚至没有更进一步

答:

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
没有子句的语句是这个问题的核心。“如果条件不满足,什么都不会发生”过去曾多次咬过我。ifelse