0
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)

Above is my code which I wrote for someone, the loop does what I was intending for it to do but there is something wrong. After the "wait_for" times out, the bot crashes for some reason. I can't seem to find any reason as to why.

All variables used are defined, and there are no errors the bot just dies after it times out.

Any idea why that might be?

enter image description here

Image of terminal after bot crashed: [edit]

enter image description here

3
  • Where exactly does it crash? What traceback does it show? Please add this information! Commented May 17, 2021 at 8:27
  • @itzFlubby it just crashes (the bot goes down/offline) without giving any traceback Commented May 17, 2021 at 8:31
  • 1
    What does you bot do after the while condition:? It looks like await self.client.wait_for raises asyncio.TimeoutError and therefore exits your while-statement after the timeout. Commented May 17, 2021 at 8:34

1 Answer 1

1

According to wait_for documentation, providing a timeout time (default to None) will raise an asyncio.TimeoutError.

In your code:

try:
   msg = await self.client.wait_for('message', check=check, timeout = 60)
except asyncio.TimeoutError:
   condition = False
   break

This leads you to breaking out of the while loop (note that setting the condition to false doesn't change anything since you are out of the loop anyway). It does not look like the bot is crashing, it looks more like the bot simply finished executing the program.

Maybe what you want is to NOT set timeout.

Sign up to request clarification or add additional context in comments.

2 Comments

But it's inside a command, so technically it should finish the command when I break out of the loop, I still don't get why the entire bot goes offline due to this.
I found the issue! The code I posted was first part of the command (an if statement) where args weren't provided, so once I broke out of the while loop it moved to the next segment of the code where the argsparser got no arguments and because of which the bot crashed. I just added a return at the end of the first if statement and it works now!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.