Skip to content

Instantly share code, notes, and snippets.

@aiden2480
Created August 28, 2022 07:37
Show Gist options
  • Save aiden2480/f81a922bd54d6526c750cc525ced9f07 to your computer and use it in GitHub Desktop.
Save aiden2480/f81a922bd54d6526c750cc525ced9f07 to your computer and use it in GitHub Desktop.
Searches your discord account for any folders with the colour #09090A and prevents users in those servers from being able to DM you if one of those servers is your only common server. This is useful for hiding away bot lists and the like
import requests
sess = requests.Session()
sess.headers.update({
"Content-type": "application/json",
"Authorization": "<replace your discord token here>",
})
# Define methods
def get_guilds_in_muted_folder() -> list:
"""
Get all guilds in any folder with the hex code set to #09090A,
which is an invisible folder in Discord's dark mode client.
"""
req = sess.get("https://discord.com/api/v6/users/@me/settings")
req.raise_for_status()
folders = req.json()["guild_folders"]
folders = [f for f in folders if f["color"] == 0x09090A]
guildids = [folder["guild_ids"] for folder in folders]
return [item for sublist in guildids for item in sublist]
def add_restricted_guilds(guilds: list):
"""
Adds guilds to the restricted list, doesn't overwrite old ones
"""
req = sess.get("https://discord.com/api/v6/users/@me/settings")
req.raise_for_status()
current = req.json()["restricted_guilds"]
current += guilds
req = sess.patch("https://discord.com/api/v6/users/@me/settings", json={"restricted_guilds": current})
req.raise_for_status()
# Call methods
if __name__ == "__main__":
in_muted_folder = get_guilds_in_muted_folder()
add_restricted_guilds(in_muted_folder)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment