Skip to content

Instantly share code, notes, and snippets.

@IMcPwn
Forked from niahoo/delete-all-messages.js
Last active July 12, 2023 19:41
Show Gist options
  • Star 93 You must be signed in to star a gist
  • Fork 41 You must be signed in to fork a gist
  • Save IMcPwn/0c838a6248772c6fea1339ddad503cce to your computer and use it in GitHub Desktop.
Save IMcPwn/0c838a6248772c6fea1339ddad503cce to your computer and use it in GitHub Desktop.
Delete all messages in a Discord channel
// Turn on Developer Mode under User Settings > Appearance > Developer Mode (at the bottom)
// Then open the channel you wish to delete all of the messages (could be a DM) and click the three dots on the far right.
// Click "Copy ID" and paste that instead of LAST_MESSAGE_ID.
// Copy / paste the below script into the JavaScript console.
// If you're in a DM you will receive a 403 error for every message the other user sent (you don't have permission to delete their messages).
var before = 'LAST_MESSAGE_ID';
clearMessages = function(){
const authToken = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/"/g, "");
const channel = window.location.href.split('/').pop();
const baseURL = `https://discordapp.com/api/channels/${channel}/messages`;
const headers = {"Authorization": authToken };
let clock = 0;
let interval = 500;
function delay(duration) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), duration);
});
}
fetch(baseURL + '?before=' + before + '&limit=100', {headers})
.then(resp => resp.json())
.then(messages => {
return Promise.all(messages.map((message) => {
before = message.id;
return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
}));
}).then(() => clearMessages());
}
clearMessages();
@TheOutride
Copy link

Hey guys sorry about disappearing. Been busy. Apparently, like an absolute noob, I left my auth token on the original code. Deleted that entire repository and made a new one.

https://github.com/TheOutride/Discord-Deleting-DM/blob/master/Delete-Messages.js

Please drop any issues over there. Someone had made a pull request to update the ReadMe. I didn't have time to update it before deleting it.

@Altoids1 No problem. Thanks for the code really, I didn't do a whole lot beyond looping it

@MattAlp
Copy link

MattAlp commented Feb 16, 2019

@TheOutride I'm getting an "VM324:44 Uncaught (in promise) TypeError: messages.map is not a function
at fetch.then.then.messages (:44:32)" error, do you know what might be causing that

Copy link

ghost commented Feb 20, 2019

@TheOutride
Yes its working
, but no any different from mine (/Altoids1's) except for more error messages, some "completed randomnumber" message loops, and a bit faster progress (maybe just illusion). Thanks for credits anyway. Keep it up, bro.

Copy link

ghost commented Feb 20, 2019

btw, some other also cant insert code via webversion?
Get "Scam Warning" and nothing happening, - in normal desktop-app everything is still working fine.

Copy link

ghost commented Feb 22, 2019

I found something much more handy:

  1. Download AutoHotkey:
    https://www.autohotkey.com/
  2. Save a script with a notepad: Name.ahk
    `

^j::

Loop, 100
{
send, {Up}
send, ^a
send, {BS}
send, {Enter}
send, {Enter}
sleep, 500
}
Return

`
3. Go in Disocrd, choose a Channel, start Autohotkey/Script (You have the Icon in tray now)
4. Run the script with ur choosen hotkey (default CTRL + J) (the first letters in script, self explaining)
Now you see how its deleting, without any token sht, without any javascript and console..
No any of this complicated crap is need any more... finaly...

For better handle:
Search ur messages via Discord-Search Funktion, Jump to it, run script, toggle between recent and all for update.
At any time you need to start again (reached the 100 or whatever) - or just increase the value (not tested yet).
If you want to stop (for example choose channel, doing some other: Rightclick on tray-icon and pause scripts.
When you are done, just close the application: Rightclickl on tray-icon and exit.

Source:
https://www.youtube.com/watch?v=7vYQATyqpos

Use it on own risk (for me its working fine)

Copy link

ghost commented Mar 4, 2019

This works for me 3/3/19

var before = 'LAST_MESSAGE_ID';
clearMessages = function(){
var authToken = 'ENTER_HERE_UR_TOKEN'
const channel = window.location.href.split('/').pop();
const baseURL = https://discordapp.com/api/channels/${channel}/messages;
const headers = {"Authorization": authToken };

let clock = 0;
let interval = 500;

function delay(duration) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), duration);
});
}

fetch(baseURL + '?before=' + before + '&limit=100', {headers})
.then(resp => resp.json())
.then(messages => {
return Promise.all(messages.map((message) => {
before = message.id;
return delay(clock += interval).then(() => fetch(${baseURL}/${message.id}, {headers, method: 'DELETE'}));
}));
}).then(() => clearMessages());
}
clearMessages();

To find token: Using F12 > Application > Storage >Discord.app.com > Then look for token, sometimes you have to refresh and it's usually the last Key - copy it quickly

@NeutronBlast
Copy link

I found something much more handy:

  1. Download AutoHotkey:
    https://www.autohotkey.com/
  2. Save a script with a notepad: Name.ahk
    `

^j::
Loop, 100
{
send, {Up}
send, ^a
send, {BS}
send, {Enter}
send, {Enter}
sleep, 500
}
Return

`
3. Go in Disocrd, choose a Channel, start Autohotkey/Script (You have the Icon in tray now)
4. Run the script with ur choosen hotkey (default CTRL + J) (the first letters in script, self explaining)
Now you see how its deleting, without any token sht, without any javascript and console..
No any of this complicated crap is need any more... finaly...

For better handle:
Search ur messages via Discord-Search Funktion, Jump to it, run script, toggle between recent and all for update.
At any time you need to start again (reached the 100 or whatever) - or just increase the value (not tested yet).
If you want to stop (for example choose channel, doing some other: Rightclick on tray-icon and pause scripts.
When you are done, just close the application: Rightclickl on tray-icon and exit.

Source:
https://www.youtube.com/watch?v=7vYQATyqpos

Use it on own risk (for me its working fine)

not working, it doesn't delete anything.

@jackblk
Copy link

jackblk commented Mar 5, 2019

var before = 'LAST_MESSAGE_ID';
clearMessages = function(){
	const authToken = "ENTER_TOKEN_HERE";
	const channel = window.location.href.split('/').pop();
	const baseURL = `https://discordapp.com/api/channels/${channel}/messages`;
	const headers = {"Authorization": authToken };

	let clock = 0;
	let interval = 500;

	function delay(duration) {
		return new Promise((resolve, reject) => {
			setTimeout(() => resolve(), duration);
		});
	}

	fetch(baseURL + '?before=' + before + '&limit=100', {headers})
		.then(resp => resp.json())
		.then(messages => {
		return Promise.all(messages.map((message) => {
			before = message.id;
			return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
		}));
	}).then(() => clearMessages());
}
clearMessages();

This code still works (original code). Just replace id of the last message and token then you're good to go.

@protected22
Copy link

Doesn;t work. I still see my messages. even after reloading or logging in again

Copy link

ghost commented Mar 8, 2019

I found something much more handy:

  1. Download AutoHotkey:
    https://www.autohotkey.com/
  2. Save a script with a notepad: Name.ahk
    `

^j::
Loop, 100
{
send, {Up}
send, ^a
send, {BS}
send, {Enter}
send, {Enter}
sleep, 500
}
Return

`
3. Go in Disocrd, choose a Channel, start Autohotkey/Script (You have the Icon in tray now)
4. Run the script with ur choosen hotkey (default CTRL + J) (the first letters in script, self explaining)
Now you see how its deleting, without any token sht, without any javascript and console..
No any of this complicated crap is need any more... finaly...
For better handle:
Search ur messages via Discord-Search Funktion, Jump to it, run script, toggle between recent and all for update.
At any time you need to start again (reached the 100 or whatever) - or just increase the value (not tested yet).
If you want to stop (for example choose channel, doing some other: Rightclick on tray-icon and pause scripts.
When you are done, just close the application: Rightclickl on tray-icon and exit.
Source:
https://www.youtube.com/watch?v=7vYQATyqpos
Use it on own risk (for me its working fine)

not working, it doesn't delete anything.

Tested right now. Its working, you did something wrong.
Have you followed exactly the instructions? Remember you have to save the quotes plaintext as Your-name.ahk
To start you need to open the program via the file, go in channel and pressing CTRL and J same time.

Copy link

ghost commented Mar 8, 2019

Doesn;t work. I still see my messages. even after reloading or logging in again

Tested mine? Worked still weeks ago, since there I do it with the autohotkey program.

@cedws
Copy link

cedws commented Mar 8, 2019

I've been working on another solution for Discord message deletion.
https://github.com/c-edw/discord-delete

Copy link

ghost commented Mar 10, 2019

https://github.com/c-edw/discord-delete

So this thing delete EVERYTHING in discord?
Would be a good solution when I creating new Account.

@JoannaMakary
Copy link

This script used to work for me until a few updates ago.

Uncaught (in promise) TypeError: messages.map is not a function
at fetch.then.then.messages (:20:31)

is the error I started to get recently.

@simplycontent
Copy link

I've been working on another solution for Discord message deletion.
https://github.com/c-edw/discord-delete

Is this legit? I like the idea of it!

Copy link

ghost commented Mar 21, 2019

https://gist.github.com/z861gz6wb2/fd89c6cf9db9662c68698736d937f0d2
Hey guys, I updated the Discord "mass message deletion browser script" with LOTS of improvements and bug fixes. I rewrote most parts of the script. Now you don't even need to fill in your auth token, user id, channel id. The message id part is optional. My script fetches all the needed information for you so all you gotta do is copy and paste. It works anywhere, in channels and DMs. It even lets you know when it's finished deleting all the messages, so just chill until you get the alert. I made the alert tell you how many messages it deleted too so lots of good stuff. Feel free to look at the code and tweak it anyway you like. You can even turn it into a bookmark for easy launching, just use the "javascript:" prefix followed by the code (run my script through a JS minifier first) then put it in the URL box when adding it as a bookmark.

EDIT: People are reporting that this script fails to grab the auth token in chromium browsers like Opera and Brave. However I tested it in Chrome Canary and it worked. So if you don't want to use Chrome, you can fill in your token manually.

@testing123the
Copy link

testing123the commented Mar 22, 2019

https://gist.github.com/z861gz6wb2/fd89c6cf9db9662c68698736d937f0d2
Hey guys, I updated the Discord "mass message deletion browser script" with LOTS of improvements and bug fixes. I rewrote most parts of the script. Now you don't even need to fill in your auth token, user id, channel id. The message id part is optional. My script fetches all the needed information for you so all you gotta do is copy and paste. It works anywhere, in channels and DMs. It even lets you know when it's finished deleting all the messages, so just chill until you get the alert. I made the alert tell you how many messages it deleted too so lots of good stuff. Feel free to look at the code and tweak it anyway you like. You can even turn it into a bookmark for easy launching, just use the "javascript:" prefix followed by the code (run my script through a JS minifier first) then put it in the URL box when adding it as a bookmark.

I replied to your code that I'm getting this error that it cannot find the IDs:
"VM369:20 Uncaught TypeError: Cannot read property 'replace' of undefined
at :20:62
at :84:3"

EDIT:
I can confirm it works if you do it manually, as the Authtoken just appears for a brief 1 sec when you load the page and the script cannot find it afterwards when it runs.
Manually:

  1. Simply use the original method to catch it (I used screenshot and typed it in manually, cause I'm too slow to copy+paste or it doesn't work?!).
  2. Paste/type it here <<const authToken = frame.contentWindow.localStorage.token.replace(/"/g, "");>>, meaning you replace <<frame.contentWindow.localStorage.token.replace(/"/g, "")>> with <<"YOUR_AUTHTOKEN">>
    (I used <<>> to quote, so remove those and don't forget to add the "")
  3. Thank the guys that helped with the code! <3

@victornpb
Copy link

victornpb commented Apr 8, 2019

UPDATE: 2019-APRIL

I wrote a mass delete script properly, it logs the messages being deleted along with a progress on a popup.
it also gives you an estimated time!

https://gist.github.com/victornpb/135f5b346dea4decfc8f63ad7d9cc182

@thegohst
Copy link

thegohst commented Jun 3, 2019

There another solution , using android mobile application to delete the messages , it work , i tested it

https://play.google.com/store/apps/details?id=com.mlika.discorddelete.free

@TheOutride
Copy link

Please be EXTREMELY careful of downloading applications. Make sure you trust them with the permissions you give them.

Code currently working found here: https://github.com/TheOutride/Discord-Deleting-DM

@viasux
Copy link

viasux commented Aug 25, 2019

Doesn't work anymore.

@victornpb
Copy link

victornpb commented Aug 29, 2019

Doesn't work anymore.

EDITED: WORKING AS JAN-2020
Take a look at this https://github.com/victornpb/deleteDiscordMessages
full disclaimer, I'm the author.

@viasux
Copy link

viasux commented Aug 29, 2019

Doesn't work anymore.

WORKING AS AUG-2019
Take a look at this https://github.com/victornpb/deleteDiscordMessages
full disclaimer, I'm the author.

Works! thank you! - just wish I could delete all messages in all channels :P

@gtkiller422
Copy link

Doesn't work anymore.

WORKING AS AUG-2019
Take a look at this https://github.com/victornpb/deleteDiscordMessages
full disclaimer, I'm the author.

didnt work man

@victornpb
Copy link

WORKING AS AUG-2019
Take a look at this https://github.com/victornpb/deleteDiscordMessages
full disclaimer, I'm the author.

didnt work man

It is working as JAN-2020

@SmilingStallman
Copy link

Works for me still on Chromium, but not firefox. Works on most channels, that is. For one channel I do get

authorID="ommited" guildId="618621882110967809" channelId="663328918719168514" afterMessageId="" beforeMessageId="" hasLink=false hasFile=false
Error searching messages, API responded with status 403!
{"message":"Missing Access","code":50001}

Despite being able to hand delete messages in that channel aslo

@jaytareen
Copy link

I was able to delete only my messages from the private text message. How can I delete the other person message. Please advice

@ayoubkhan558-zz
Copy link

I found this repo pretty useful. Its fast and easy to use.

https://github.com/victornpb/deleteDiscordMessages

@DakotaIrsik
Copy link

Senior Software Developer here. Nice work, thanks for saving me some time!

@jsoctocat
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment