Skip to content

Instantly share code, notes, and snippets.

@nobbele
Created December 12, 2018 16:36
Show Gist options
  • Save nobbele/12b60609c241cab16b0756b1534bdbec to your computer and use it in GitHub Desktop.
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
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