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();
@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