Last active
February 17, 2019 13:38
-
-
Save gerardmarquina/f2438c124deee80e795d4cb3c40e83ff to your computer and use it in GitHub Desktop.
Fixed script to delete discord messages with new instructions provided because token is not present in localstorage anymore. Credits to "Niahoo" and "CarletonStuberg"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Credits to https://gist.github.com/niahoo/c99284a8908cd33d59b4aff802179e9b and https://gist.github.com/CarletonStuberg/0c838a6248772c6fea1339ddad503cce | |
// 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 on your last message. | |
// Click "Copy ID" and paste that instead of LAST_MESSAGE_ID. | |
// Open the console with control+shift+i | |
// Go to network tab | |
// Move between two channels | |
// You should see a new request that says something along the lines "messages?limit=50" | |
// Open the request and find the header "authorization" and copy the RequestHeaders (you can save the authorization token for later). | |
// Go to the application tab in the console | |
// Go to http://discordapp.com under "Local Storage" | |
// Make sure a key with the token doesn't exist yet | |
// Create a new key with the name "token" and the value from the Authorization/Requestheaders. | |
// 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(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment