LoginFailure: Improper token (401) — TOKEN_INVALID: how to fix
What this error means
Your Discord bot can't authenticate because its token is missing, wrong, or no longer valid (the Discord API responds with HTTP 401 Unauthorized). Typical messages:
# discord.js
Error [TOKEN_INVALID]: An invalid token was provided.
# discord.py
discord.errors.LoginFailure: Improper token has been passed.
Why it happens
- The token was regenerated in the Developer Portal (the old one immediately stops working).
- The token was reset or revoked for security.
- It's misconfigured — extra spaces or quotes, or the code is reading the wrong variable.
How to fix it
1. Regenerate the token. In the Discord Developer Portal, open your application → Bot → Reset Token, and copy the new value.
2. Update the token where it's stored. Replace it in your .env file or config.json (and in your Square Cloud environment variables, if you use them). Never commit the token to GitHub.
3. Keep the library up to date. npm install discord.js@latest or pip install -U discord.py.
4. Restart the application.
Related
Setting up a bot for the first time? See How to create a Discord bot from scratch and How to host a Discord bot.
Updated on: 06/13/2026
Thank you!
