Last active
October 28, 2020 14:26
-
-
Save chancity/0fb6d84f7b540eeb186c2a0cee473689 to your computer and use it in GitHub Desktop.
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
function createMessageDeleter({ | |
rateLimitMs, | |
channel, | |
authorization, | |
xSuperProperties, | |
authorId | |
}) { | |
function deleteMessage(message) { | |
if(message.author.id !== authorId) { | |
return; | |
} | |
return fetch(`https://discordapp.com/api/v8/channels/${channel}/messages/${message.id}`, { | |
credentials: "include", | |
headers: { | |
"accept": "*/*", | |
"accept-language": "en-US", | |
"authorization": authorization, | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin", | |
"x-super-properties": xSuperProperties | |
}, | |
referrer: `https://discordapp.com/channels/@me/${channel}`, | |
referrerPolicy: "no-referrer-when-downgrade", | |
body: null, | |
method: "DELETE", | |
mode: "cors" | |
} | |
); | |
} | |
async function getMessagesBefore(message) { | |
const response = await fetch(`https://discordapp.com/api/v8/channels/${channel}/messages?before=${message.id}&limit=50`, { | |
credentials: "include", | |
headers: { | |
"accept": "*/*", | |
"accept-language": "en-US", | |
"authorization": authorization, | |
"sec-fetch-mode": "cors", | |
"sec-fetch-site": "same-origin" | |
}, | |
referrer: `https://discordapp.com/channels/@me/${channel}`, | |
referrerPolicy: "no-referrer-when-downgrade", | |
body: null, | |
method: "GET", | |
mode: "cors" | |
}); | |
return response.json(); | |
} | |
async function recursiveDeleteAllMessages(messages) { | |
if (messages.length > 0) { | |
for (let index = 0; index < messages.length; index++) { | |
await new Promise(r => setTimeout(r, rateLimitMs)); | |
await deleteMessage(messages[index]); | |
} | |
const lastMessage = messages[messages.length - 1]; | |
return recursiveDeleteAllMessages(await getMessagesBefore(lastMessage)); | |
} | |
return true; | |
} | |
async function deleteAllMessages(startId) { | |
const startMessages = await getMessagesBefore({id: startId}); | |
return recursiveDeleteAllMessages(startMessages); | |
} | |
return { | |
deleteAllMessages | |
} | |
} | |
const channelClient = createMessageDeleter({ | |
rateLimitMs: 600, //time between deletes | |
channel: '', //get from developer console network request | |
xSuperProperties: "", //get from developer console network request | |
authorization: "", //get from developer console network request | |
authorId: 0 | |
}) | |
//Pass the starting messageId | |
channelClient.deleteAllMessages(771015313470783529) | |
.then((done) => console.log(done)) | |
.catch(error => console.log(error)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment