> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Discord Bot Errors on Square Cloud: LoginFailure, Disallowed Intents, Lavalink 1006

> Fix LoginFailure Improper token has been passed, TOKEN_INVALID, Used disallowed intents, Message Content Intent, Lavalink connection closed with code 1006, and Discord bots going offline on Square Cloud.

Discord bot errors on Square Cloud usually trace back to the token, the gateway intents, or a version mismatch with Lavalink. Match the exact message below.

## "LoginFailure: Improper token has been passed" / TOKEN\_INVALID

**What it means:** the library rejects the token you're logging in with (discord.js throws `LoginFailure`/"An invalid token was provided"; other stacks surface a 401 `TOKEN_INVALID`).

**Why it happens:**

* The token was regenerated or revoked in the Discord Developer Portal. Generating a new token instantly invalidates the old one everywhere it's used.
* The token string has extra spaces or quotes copied in by accident.
* The code is reading the wrong environment variable.

**How to fix:**

1. Go to the [Developer Portal](https://discord.com/developers/applications) → your application → **Bot** → **Reset Token**.
2. Update the token in this application's **Environment Variables** in the Square Cloud dashboard. Never commit the token in a file that gets uploaded in the `.zip`.
3. Double-check there are no stray spaces or quotes around the value.
4. Update the library (`discord.js@latest` or `pip install -U discord.py`).
5. Restart the application.

<Warning>Never hardcode your bot token in source files. Always read it from an environment variable set in the dashboard.</Warning>

## "Used disallowed intents" / Message Content Intent

**What it means:** the bot logs in and appears online, but ignores every message, or the gateway rejects the connection with "used disallowed intents".

**Why it happens:** since 2022, **Message Content** is a privileged intent. Without it explicitly enabled in both places, message content arrives empty (or the gateway connection is refused if your code declares an intent that isn't enabled for the app).

**How to fix, in both places:**

1. Discord Developer Portal → your application → **Bot** → **Privileged Gateway Intents** → enable **Message Content Intent**.
2. Declare it in code as well:

```javascript theme={null}
// discord.js
const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});
```

```python theme={null}
# discord.py
intents = discord.Intents.default()
intents.message_content = True
client = commands.Bot(command_prefix="!", intents=intents)
```

3. Restart the application.

<Note>Once a bot passes 100 servers, privileged intents (including Message Content) also require approval from Discord, requested from the same Developer Portal page.</Note>

## Lavalink connection closed with code 1006

**What it means:** the bot's Lavalink client closes the WebSocket abnormally with code 1006, often preceded by "Unexpected server response: 400".

**Why it happens:** this is a version mismatch. Lavalink v4 is REST-based and is incompatible with a client wrapper built for v3, so the handshake fails and the socket closes with 1006.

**How to fix:**

1. Align your bot's Lavalink client wrapper version with the Lavalink server's major version (v3 client with v3 server, v4 client with v4 server).
2. On Square Cloud, the Lavalink server itself binds port `80`, but your bot must connect to it through the edge on port `443` with `secure: true`.
3. Restart both the Lavalink application and the bot application after fixing the version mismatch.

For the full Lavalink hosting setup (config file, port, deployment), see the [Lavalink server tutorial](/en/tutorials/how-to-create-your-lavalink-server).

## Bot goes offline after working locally

**What it means:** the bot logs in fine when you run it on your machine, but goes offline (or restarts repeatedly) once deployed.

**Why it happens, most commonly:**

* An unstable connection at the gateway level with no reconnect handling.
* Conflicting or incompatible dependency versions between what you tested locally and what's in your dependencies file.
* Discord API abuse triggers (an account gets a notification email in this case) from hitting rate limits too aggressively.

**How to fix:**

1. Check the application's logs in the dashboard first, they show the actual crash reason.
2. Add error handlers so a transient error doesn't crash the process: `process.on("unhandledRejection", ...)` and `client.on("error", ...)` in discord.js, equivalent handling in discord.py.
3. Square Cloud auto-restarts a crashed app (`AUTORESTART` in the manifest) when the previous uptime was over 60 seconds, the exit status was 1, and it hasn't auto-restarted in the last 60 minutes. This keeps the bot alive through transient errors, but it never fixes an underlying code error, syntax error, or missing dependency, those still need a fix in the code.
4. Watch for Discord API rate limits (429): the global limit is about 50 requests/second per bot token, with tighter per-route buckets (channel create/edit allows roughly 2 changes per 10 minutes per channel). Cache aggressively, use an async queue that respects the `X-RateLimit-Remaining`/`X-RateLimit-Reset-After` headers, and use webhooks for mass sends.

See the full [Discord bot hosting tutorial](/en/tutorials/bots/discord) for setup from scratch.

<Tip>If the logs don't point to a clear cause, our support team can help you dig further.</Tip>

## Contact us

If you continue facing **technical difficulties**, our **specialized support team** is available to assist you. [**Contact us**](https://squarecloud.app/en/support) and we'll be happy to help you resolve any issue — support quality is a big part of why developers rate Square Cloud [**4.9/5 across 402 reviews**](https://www.trustpilot.com/review/squarecloud.app) on Google and Trustpilot.
