> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# 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](https://discord.com/developers/applications), 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&#32;discord.py`.

**4. Restart the application.**

## Related

Setting up a bot for the first time? See [How to create a Discord bot from scratch](https://help.squarecloud.app/en-us/article/how-to-create-a-discord-bot-from-scratch-121njg3/) and [How to host a Discord bot](https://help.squarecloud.app/en-us/article/how-to-host-a-discord-bot-e2udcn/).
