Python 当循环崩溃机器人

Python 当循环崩溃机器人,python,discord,discord.py,Python,Discord,Discord.py,上面是我为某人编写的代码,循环执行了我希望它执行的操作,但出现了一些错误。“等待”超时后,bot会因某种原因崩溃。我似乎找不到任何理由来解释原因 使用的所有变量都已定义,并且没有错误 机器人超时后就死了 知道为什么吗 bot崩溃后的终端图像:[编辑] 根据,提供超时时间(默认为无)将引发asyncio.TimeoutError 在代码中: 试试看: msg=wait self.client.wait_for('message',check=check,timeout=60) 除asyncio.

上面是我为某人编写的代码,循环执行了我希望它执行的操作,但出现了一些错误。“
等待
”超时后,bot会因某种原因崩溃。我似乎找不到任何理由来解释原因

使用的所有变量都已定义,并且没有错误 机器人超时后就死了

知道为什么吗

bot崩溃后的终端图像:[编辑]

根据,提供超时时间(默认为无)将引发
asyncio.TimeoutError

在代码中:

试试看:
msg=wait self.client.wait_for('message',check=check,timeout=60)
除asyncio.TimeoutError外:
条件=假
打破
这会导致您中断while循环(请注意,将条件设置为false不会改变任何东西,因为您已经退出了循环)。看起来机器人并没有崩溃,更像是机器人完成了程序的执行


也许您不想设置
超时

它到底在哪里崩溃?它显示了什么追溯?请添加此信息@itzFlubby它只是崩溃(bot关闭/脱机)而不提供任何回溯。在
状态:
之后,bot会做什么?它看起来像是
wait self.client.wait_for
引发
asyncio.TimeoutError
,因此在超时后退出while语句。但它在命令内部,所以从技术上讲,当我跳出循环时它应该完成命令,我仍然不明白为什么整个bot会因此脱机。我发现了问题!我发布的代码是命令(if语句)的第一部分,其中没有提供args,因此一旦我跳出while循环,它就会移动到代码的下一段,argsparser没有参数,因此bot崩溃。我刚刚在第一个if语句的末尾添加了一个return,现在就可以了!
while condition:
            try:
                msg = await self.client.wait_for('message', check=check, timeout = 60)
            except asyncio.TimeoutError:
                condition = False
                break
            else:
                my_num = msg.content.split(' ')
                if len(my_num) > 2:
                    await ctx.send("Seems like you added too many arguments... Only use `category` `number`", delete_after=2)
                category = my_num[0]
                try:
                    index = int(my_num[1])
                except ValueError:
                     await ctx.send("The second argument needs to be an integer", delete_after=2)
                except IndexError:
                     await ctx.send("Provide two arguments: `category` `number`  (example: plants 3)")
                if category.lower() == "plants":
                    try:
                        my_query = new_list[index-1]
                    except IndexError:
                        await ctx.send("the number you wrote doesn't exist!", delete_after=2)
                    queried_potion = all_items[my_query]
                    try:
                        signs = queried_potion['sign']
                    except KeyError:
                        signs = []
                    try:
                        symbols = queried_potion['symbol']
                    except KeyError:
                        symbols = []
                    sign = " | ".join(signs) if len(signs) != 0 else "None"
                    symbol = " | ".join(symbols) if len(symbols) != 0 else "None"      
                    em = discord.Embed(title=f"Information for: {my_query}", description= f"**Symbols:** \n{symbol} \n\n**Signs:**\n {sign}", color = self.client.theme)
                    await mess.edit(embed=em)