Skip to content

Instantly share code, notes, and snippets.

@mechawrench
Last active December 3, 2017 04:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mechawrench/fc6ed1f43fa97e8ae9be34985502dc1b to your computer and use it in GitHub Desktop.
Save mechawrench/fc6ed1f43fa97e8ae9be34985502dc1b to your computer and use it in GitHub Desktop.
Discord delete own PM's
var before = LASTMESSAGEID;
clearMessages = function(){
const authToken = "TOKEN";
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