Last active
December 3, 2017 04:27
-
-
Save mechawrench/fc6ed1f43fa97e8ae9be34985502dc1b to your computer and use it in GitHub Desktop.
Discord delete own PM's
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
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