Last active
          May 6, 2025 20:46 
        
      - 
      
 - 
        
Save SkyfallWasTaken/f35a11cd8c49efaa375b3b30b856c1a4 to your computer and use it in GitHub Desktop.  
    Mass-leave Discord servers
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | # /// 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()) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
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