Cleaning all messages on slack channel

Jerry Han
Jerry Han
Jul 27, 2017 · 3 min read

Recently, One of our slack channel had got so dirty.

I tried to delete all garbage messages on it. But How about for over 10k messages on it?

Yes, you can do archive that channel. But How about for the general channel?


Let’s clean whole messages of a channel by little programatic way.


Using python and ‘slack-cleaner’

  • You have to have installed python and pip by yourself.
  • install slack-cleaner via pip
pip install slack-cleaner 
(please do it with 'sudo' when you got Permission denied error)
  • get the target channel name to delete
  • verifying the expected run
    You can verify the result of ‘slack-cleaner’ running
slack-cleaner --token=[your token here] --message --channel general --user "*"
  • after verifying, let’s execute delete by adding ‘perform’ option.
slack-cleaner --token=[your token here] --message --channel general --user "*" --perform

Using node and ‘delete-channel-message.js’

  • You have to have installed node by yourself.
  • download ‘delete-channel-message.js’
wget https://gist.githubusercontent.com/firatkucuk/ee898bc919021da621689f5e47e7abac/raw/8c3b420fe3e334d740957a229937cdcbd10c0063/delete-channel-messages.js
(You can download this file via web browser. Just do as your way)
  • set the target token and target channel in .js file.
    Before edit the .js file, you should know the your channel id (not channel name) by browsing your target channel on the browser.
    If your goto your target channel in browser, there will be shown the hidden channel id.
    When you go to the your target channel by these url :
    >> https://yourcompany.slack.com/messages/general/
    It will be changed like this :
    >> https://yourcompany.slack.com/messages/[channel id hash value]/…
    You should use the this [channel id hash value].
// CONFIGURATION #######################################################################################################var token          = 'your api token here';
var channel = 'your channel id hash value';
  • and run it with node.
node delete-channel-messages.js
(You may get 'TypeError: Cannot read property 'length' of undefined' when you typed 'channel name'. Please set the correct 'channel id hash value' to fix it.)

That’s it.


My prefer is node one.

Because the python one was service denied after some messages deleted.
It caused by not enough delay time. I maybe send pull request for it.

The node one works fine.


Thanks for reading.

Jerry Han

Written by

Jerry Han

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade