Skip to content
Advertisement

Discord.py (rewrite): Error Handling “Improper Token” In Function

I feel like I’m missing a simple way to solve this problem, but I can’t seem to find a way to handle the discord.errors.LoginFailure: Improper token has been passed. error. What I’m trying to do is run a function that essentially runs a bot and repeats itself if it comes across any errors (with try: and except:) and if it catches the ‘improper token’ error then change a setting in my code and retry it.

What I believe is happening is that try/except isn’t catching the error and it stops the program (printing the entire error in the process). I’ve tried some quick solutions like making the function into a while statement and until it reaches the end of the program it will keep repeating itself, however without catching the error I can’t continue any code.

My code is messy and has to do with a lot of variables that are defines earlier in this large python file, so I won’t show my entire function.

Here is the simplified version:

JavaScript

The full error message:

JavaScript

As of writing this I found ‘Task exception never retrieved’ is this anything of importance or is that the usual ‘improper token’ error?

Thank you, sorry in advance for my bad coding practices and lack of experience using Stack Overflow.

Advertisement

Answer

Try this. I haven’t tried it myself. This is my best answer as to what I can understand from your problem and error message:

JavaScript
Advertisement