Skip to content

Instantly share code, notes, and snippets.

@skyfallwastaken
Last active February 20, 2026 04:55
Show Gist options
  • Select an option

  • Save skyfallwastaken/f35a11cd8c49efaa375b3b30b856c1a4 to your computer and use it in GitHub Desktop.

Select an option

Save skyfallwastaken/f35a11cd8c49efaa375b3b30b856c1a4 to your computer and use it in GitHub Desktop.
Mass-leave Discord servers
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "asyncio",
# "httpx",
# ]
# ///
# Run this with `uv`: `uv run leave.py`
import asyncio
import httpx
TOKEN = "YOUR_CLIENT_TOKEN"
# Server IDs which you wish to stay in
WHITELIST = [
1157330843518386281,
# ...
]
HEADERS_GET = {
"Authorization": TOKEN,
"User-Agent": "DiscordBot (https://discord.com, v1)"
}
async def leave_guild(client, guild_id):
url = f"https://discord.com/api/v10/users/@me/guilds/{guild_id}"
response = await client.delete(url, headers=HEADERS_GET)
if response.status_code == 204:
print(f"✅ Left guild {guild_id}")
await asyncio.sleep(2.5)
else:
print(f"❌ Failed to leave guild {guild_id}: {response.status_code} - {response.text}")
await asyncio.sleep(5)
async def main():
async with httpx.AsyncClient() as client:
response = await client.get("https://discord.com/api/v10/users/@me/guilds", headers=HEADERS_GET)
if response.status_code != 200:
print(f"❌ Error fetching guilds: {response.status_code} - {response.text}")
return
guilds = response.json()
print(f"🔍 You are in {len(guilds)} guilds.")
for guild in guilds:
guild_id = int(guild["id"])
if guild_id not in WHITELIST:
await leave_guild(client, guild_id)
else:
print(f"⏭️ Skipping whitelisted guild {guild_id}")
if __name__ == "__main__":
asyncio.run(main())
@skyfallwastaken
Copy link
Author

What line? I ran this and it worked fine for me
(make sure your Python is up to date)

@airstrafes
Copy link

sorry i fixed it had a braindead moment lol can u make one for unfriending people possibly?

@skyfallwastaken
Copy link
Author

Not sure on the endpoint you need to hit for that one I’m afraid, I’ll try and look into it when I have time though

@DiptoIam
Copy link

Nice mate works fine also this only works with python 3.12 dont try with anything higher

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment