Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mass delete discord messages for a channel
// based on https://stackoverflow.com/a/49462738/1469797
// What It Do?
//
// Will delete all messages in a channel AFTER the message id specified
//
// Specify username/descriminator to only delete by user,
// or leave empty to delete all messages
// How To Use
//
// * In a web browser navigate to the channel you want to delete messages in
// * Find the message you want to start deleting from -> click three dots -> Copy ID
// * Copy all the below code into a text editor and replace values in the OPTIONS area with what you want
// (message ID is the ID you copied from above)
// * Open devtools -> console
// * Copy and paste in all the code to the console and hit enter. Will show a message in console when done (it may take awhile!)
//
// COPY EVERYTHING BELOW THIS
//
// OPTIONS
var after = 'MESSAGE_ID'; // message ID to start deleting from
// If you want to delete ALL messages after MESSAGE_ID leave the below as-is
// otherwise replace values as shown
var your_username = ''; //your username
var your_discriminator = ''; //that 4 digit code e.g. username#1234
var interval = 1; // number of seconds to wait between deletions. Increase if you are experincing HTTP 429 responses from deletions.
// don't change this
var foundMessages = false;
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;
const noFilter = your_username === '' || your_discriminator === '';
function delay(duration) {
return new Promise((resolve, reject) => {
setTimeout(() => resolve(), duration);
});
}
fetch(baseURL + '?after=' + after + '&limit=100', {headers})
.then(resp => resp.json())
.then(messages => {
return Promise.all(messages.map((message) => {
before = message.id;
foundMessages = true;
if (noFilter ||
(message.author.username == your_username
&& message.author.discriminator == your_discriminator)
) {
return delay(clock += (interval * 1000)).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
}
}));
}).then(() => {
if (foundMessages) {
foundMessages = false;
clearMessages();
} else {
console.log('DONE CHECKING CHANNEL!!!')
}
});
}
clearMessages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.