Skip to content

Instantly share code, notes, and snippets.

@phyushin
Forked from RobTheFiveNine/slack_purge.py
Created May 9, 2022 08:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phyushin/0e9232f2577cd2a53f2c0fa2cbd46561 to your computer and use it in GitHub Desktop.
Save phyushin/0e9232f2577cd2a53f2c0fa2cbd46561 to your computer and use it in GitHub Desktop.
A [not wildly efficient] script to remove your data from a Slack workspace in lieu of them providing any reasonable means of doing so.
# See https://github.com/sgratzl/slack_cleaner2 for instructions on how to install
# the pip library and how to gain an auth token
# When creating the auth token, the app you ccreate needs the following user
# token scopes:
# - users:read
# - channels:read
# - channels:history
# - chat:write
# - groups:read
# - groups:history
# - im:read
# - im:history
# - mpim:read
# - mpim:history
# - files:read
# - files:write
# After getting an auth token, make sure to put it in the `auth_token`
# variable below, as well as putting your Slack username in `your_username`
from slack_cleaner2 import SlackCleaner
auth_token = ""
your_username = ""
s = SlackCleaner("", sleep_for=1)
# Delete all messages and files
for u in s.users:
if u.name == your_username:
for f in u.files():
f.delete()
# Delete all private messages
for c in s.ims:
for msg in c.msgs():
if msg.user.name == your_username:
msg.delete()
# Delete all messages in the general channel
# (duplicate this for other channels as needed)
for msg in s.c.general.msgs(with_replies=True):
if msg.user.name == your_username:
msg.delete()
# Alternatively... if you want to delete
# all messages you have posted in every
# channel, uncomment the following block:
#for u in s.users:
# if u.name == your_username:
# for m in u.msgs():
# m.delete()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment