Created
December 12, 2018 16:36
-
-
Save nobbele/12b60609c241cab16b0756b1534bdbec to your computer and use it in GitHub Desktop.
Deletes all your messages you sent before the selected id in the current channel
This file contains hidden or 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
function loadMoreMessages() { | |
console.log("loading more messages"); | |
const buttons = document.querySelectorAll("button[type=button]"); | |
for(let i = 0; i < buttons.length; i++) { | |
if(buttons[i].innerText == "LOAD MORE MESSAGES") { | |
buttons[i].click(); | |
console.log("loaded more messages"); | |
} | |
} | |
} | |
var before = 'MESSAGE ID TO START DELETING FROM'; | |
var doStop = false; | |
function clearMessages() { | |
console.log("clearing messages"); | |
const authToken = 'AUTH TOKEN'; | |
const channel = window.location.href.split('/').pop(); | |
const baseURL = `https://discordapp.com/api/channels/${channel}/messages`; | |
const headers = {"Authorization": authToken }; | |
let clock = 0; | |
const interval = 150; | |
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(() => { console.log("cleared messages"); loadMoreMessages(); clearMessages() }); | |
} | |
clearMessages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment