22 August 2026 · 7 min read
Shard ID None Session Has Been Invalidated — Discord Bot Fix (2026)
What "Shard ID None session has been invalidated" means in discord.py and how to fix it. Covers gateway reconnection, token issues, intent problems, and choosing a host that keeps your bot stable.
[discord.gateway] Shard ID None session has been invalidated.
If you see this in your discord.py logs, your bot's gateway session was forcibly closed by Discord. This guide explains what it means, why it happens, and how to stop it recurring.
What this error actually means
Discord's gateway maintains a session for each connected bot. When Discord invalidates the session:
- The WebSocket connection closes
- discord.py logs
Shard ID None session has been invalidated - discord.py automatically tries to reconnect (start a new session)
- You see
Shard ID None has sent the RESUME payloadif reconnection succeeds
The key question is: does it reconnect by itself, or does it stay offline?
Case 1 — It reconnects within 1–2 minutes (normal)
If your logs look like this, everything is working correctly:
[discord.gateway] Shard ID None session has been invalidated.
[discord.gateway] Shard ID None has sent the RESUME payload.
[discord.gateway] Shard ID None has successfully RESUMED session abc123.
Logged in as YourBot#1234
Occasional session invalidations are normal. Discord rotates sessions as part of gateway maintenance. discord.py handles this transparently.
Action: No fix needed. Monitor frequency — if it happens more than once a day, investigate further.
Case 2 — It does not reconnect, bot stays offline
This is the problem. Common causes:
Cause A — Invalid or revoked token
discord.errors.LoginFailure: Improper token has been passed.
Your token was exposed (committed to GitHub, pasted in a chat), and Discord revoked it. Or you regenerated it in the Developer Portal without updating it in your host.
Fix:
1. Go to discord.com/developers/applications
2. Select your app → Bot tab → Reset Token
3. Update TOKEN in your host's environment variables / Secrets panel
4. Restart the bot
Cause B — Gateway rate limit (too many reconnects)
Discord rate limits bots that connect and disconnect repeatedly. This happens when: - Your bot crashes immediately on startup (bad code) and keeps restarting - Your host's auto-restart policy retries too aggressively
Fix — check for startup crashes:
# Add at the top of bot.py to see startup errors immediately
import logging
logging.basicConfig(level=logging.INFO)
Fix — slow down auto-restart:
On a VPS with systemd:
[Service]
Restart=always
RestartSec=30 # wait 30 seconds between restarts, not 1
StartLimitIntervalSec=120
StartLimitBurst=3 # only 3 restarts per 2 minutes
Cause C — Overloaded or slow host causing missed heartbeats
Discord's gateway expects a heartbeat from your bot every ~41 seconds. If your host's CPU is saturated, Python can't send the heartbeat in time and Discord closes the session.
Symptoms: Invalidation happens under heavy bot activity (many users, complex commands). Happens on cheap shared hosting.
Fix: Move to a host with dedicated CPU allocation. Check your bot for blocking operations:
# Wrong — blocks the event loop
import time
time.sleep(5)
# Right — async sleep
import asyncio
await asyncio.sleep(5)
# Wrong — synchronous database call blocks the event loop
result = db.execute("SELECT * FROM users")
# Right — run blocking calls in executor
result = await asyncio.get_event_loop().run_in_executor(None, db.execute, "SELECT * FROM users")
Cause D — Unstable host network
If your hosting server has intermittent network issues, the WebSocket connection drops before Discord receives a valid session close. Discord treats this as an unexpected disconnect and invalidates the session.
Symptoms: Invalidation happens at random times with no pattern, no high load, no code issues.
Fix: Switch to a more reliable host. On getDiscordBot, sessions typically invalidate only during planned Discord maintenance.
Monitoring session invalidations
Add logging to track how often this happens:
@bot.event
async def on_disconnect():
print(f"[{datetime.utcnow()}] Disconnected from Discord gateway")
@bot.event
async def on_resumed():
print(f"[{datetime.utcnow()}] Session resumed successfully")
@bot.event
async def on_ready():
print(f"[{datetime.utcnow()}] Connected as {bot.user}")
If you're on getDiscordBot, live logs are in the dashboard and you can see the timestamp of each event. If the bot crashes and doesn't reconnect, you'll receive a crash email.
How hosting affects session stability
| Host type | Session stability | Crash email | Auto-restart |
|---|---|---|---|
| getDiscordBot | Good — dedicated containers | ✅ Built-in | ✅ Automatic |
| Railway | Good | ❌ Configure | ✅ Automatic |
| Render Background Worker | Good | ❌ Configure | ✅ Automatic |
| Shared VPS (oversold) | Poor — noisy neighbour CPU | ❌ Configure | If configured |
| Local machine | Poor — depends on your network | ❌ | If configured |
The single biggest improvement for session stability is moving from a local machine or oversold shared host to a host with isolated container resources.
Quick diagnostic checklist
When you see Shard ID None session has been invalidated:
- Does the bot reconnect within 2 minutes? → Normal, no action needed
- Is there a
LoginFailureerror? → Token was revoked, reset it - Does it happen every time the bot starts? → Bug in startup code, check logs
- Does it happen under load? → Blocking code in event handlers or slow host
- Does it happen randomly, no pattern? → Unstable host network
Stable hosting for discord.py
The fastest way to eliminate host-related session invalidations is a managed host with isolated containers and automatic crash recovery.
Start a 30-day trial on getDiscordBot — $4.99/mo after →
See also: Discord bot keeps going offline — all causes → · How to host a Discord bot 24/7 →
FAQ
What does 'Shard ID None session has been invalidated' mean?
This is a Discord gateway error meaning your bot's session was forcibly closed by Discord's servers. Common causes: an invalid or revoked token, too many failed reconnect attempts, your bot being rate limited at the gateway level, or the host server losing connection briefly. discord.py will attempt to reconnect automatically.
How do I fix session invalidated in discord.py?
First check if your bot reconnects on its own within 1-2 minutes (normal behaviour). If it doesn't: check your token is valid, verify your host has a stable connection, and ensure you're not hitting gateway rate limits by connecting too frequently. A stable managed host eliminates most causes.
Does discord.py reconnect after session invalidated?
Yes. discord.py 2.x automatically attempts to resume the session or start a new one after a gateway invalidation. You will see 'Shard ID None has sent the RESUME payload' in logs. If reconnection fails repeatedly, the process exits and you need auto-restart configured on your host.
Will I lose messages when the session is invalidated?
Yes. Any events (messages, reactions, commands) that occur while the session is invalid and before reconnection are not delivered. This is a Discord API limitation. The faster your bot reconnects, the fewer events are missed.
How often should session invalidation happen?
Occasional session invalidations (once per week or less) are normal on any host. Daily or more frequent invalidations indicate a problem: unstable host network, overloaded server, or a buggy reconnect loop in your code.
getDiscordBot facts: Python 3.10–3.12 (discord.py, nextcord, py-cord, hikari). Paste bot.py, set TOKEN, stay on the Discord gateway. Starter $4.99/mo (1 bot, 128MB). Pro $9.99/mo (3 bots).