Delete all messages from a Slack channel

Mike R
2 min readFeb 14, 2022

if you have an active slack channel in your organization and want to delete all messages from it, as of this writing (Feb 2022) there is no way to do this via native Slack settings or tools

To delete these messages, you can run Slack-Cleaner2

step 1 — create Python virtualenv (here I use Pipenv, but can also use regular virtualenv)

mkdir ~/slack
cd ~/slack
pipenv install slack-cleaner2

create a delete script

from slack_cleaner2 import *token = "xoxp-XXXXXXXXX"
channel = "name-of-your-channel"
s = SlackCleaner(token)for msg in s.msgs(filter(match(channel), s.conversations)):
print(msg)
# delete messages, its files, and all its replies (thread)
# msg.delete(replies=True, files=True)

update your Pipfile to run this script, add the Scripts block

vim ~/slack/Pipfile[[source]]
url = "https://pypi.org/simple"
verify_ssl = true
name = "pypi"
[packages]
slack-cleaner2 = "*"
[dev-packages][requires]
python_version = "3.8"
[scripts]
clean = "python delete.py"

Step 2 — register a Slack App that will be used to delete messages

go to your slack Apps page, create a new App that will be used for authentication, give the App a meaningful name, like Slack-Channel-Msg-Delete

go to Oauth & permissions, the Token you need is the User OAuth Token, starting with xoxp-

copy this token, and add it to your delete.py script

scroll down to Scopes, and to User Token Scopes

you will need these scopes

channels:historychannels:readchat:writefiles:readfiles:writegroups:historygroups:readim:historyim:readmpim:historympim:readusers:readchannels:history

once you add the scopes, it will ask you to reinstall the App to your Workspace

Step 3 — Test the script without deleting

run your script, it should return all the chat messages within your channel

to actually delete the messages, uncomment the msg.delete line in delete.py script

pipenv run clean

this will connect to Slack, pull out all messages from your channel and delete each message in that channel

Be very careful you have the right channel selected in your delete.py, and test it first without the msg.delete line to make sure the correct messages are displaying in your terminal

for more information, see the Slack-Cleaner2 github page

--

--