NewSchokr 13 is here. A whole new UI, seven locations, snapshots and more. Read more →

Fix "An invalid token was provided" (TokenInvalid / LoginFailure)

Fix discord.js TokenInvalid and discord.py LoginFailure errors: get a fresh bot token, check your .env file and make sure the token actually loads.

Updated · 2 min read

"An invalid token was provided" means Discord rejected the token your bot used to log in, or your code passed no token at all. Reset the token in the Developer Portal, put the new one in your .env file, and make sure your code actually loads it.

What the error looks like

discord.js:

Error [TokenInvalid]: An invalid token was provided.

discord.py:

discord.errors.LoginFailure: Improper token has been passed.

Cause 1: the token is wrong or was reset

Tokens stop working when you click Reset Token, or when Discord resets it for you (for example, after detecting it in a public GitHub repository or after a crash loop exceeds the daily login limit). Fix it:

  1. Open the Discord Developer Portal and select your application.
  2. On the Bot page, click Reset Token and copy the new value.
  3. On Schokr, open the file manager, edit .env and replace the old token.
  4. Restart the server.

Cause 2: you copied the wrong value

Only the token from the Bot page works. These look similar but are not the token:

ValueWhere it's fromUsed for
Bot tokenBot pageLogging in. This is the one you need.
Client secretOAuth2 pageWeb OAuth2 logins, not bots
Application ID / Public keyGeneral information pageInvite links, slash commands, interaction verification

Cause 3: the token isn't loaded (undefined)

If your code reads the token from the environment but .env isn't loaded, the library receives undefined or an empty string. Check:

  • .env is in the right folder. It must be in the folder the bot runs from, which on Schokr is the server root, next to package.json or your main .py file.
  • The file is named exactly .env, not .env.txt or env.
  • You load it before using it. In Node.js, require('dotenv').config(); must be the first line. In Python, call load_dotenv() before os.environ[...].
  • The variable name matches. DISCORD_TOKEN in the file and process.env.DISCORD_TOKEN in code, same spelling and case.
  • dotenv or python-dotenv is in your dependencies, so it's installed on the server.

A quick check, without printing the token itself:

console.log('Token loaded:', Boolean(process.env.DISCORD_TOKEN), 'length:', process.env.DISCORD_TOKEN?.length);
print("Token loaded:", bool(os.getenv("DISCORD_TOKEN")), flush=True)

Cause 4: stray characters

  • Quotes copied into the value are usually fine with dotenv, but spaces or line breaks inside the token aren't.
  • Don't prefix it with Bot . The libraries add that themselves.
  • Re-paste the token on a single line with nothing after it.

Still failing?

Reset the token once more, paste it carefully, and restart. If you still get the error, ask in the Schokr Discord, but never post the token itself.