Last active
March 19, 2021 19:08
-
-
Save jsoctocat/586feb9e530e61e6f499f7b7773b4df3 to your computer and use it in GitHub Desktop.
Delete all messages in a particular discord server
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 deleteMessage() { | |
const author = "YOUR_ID_HERE"; | |
const authToken = "TOKEN_HERE"; | |
const guild = "SERVER_ID"; | |
const channel = window.location.href.split('/').pop(); | |
const headers = { 'Authorization': authToken, 'Content-Type': 'application/json' }; | |
let clock = 0; | |
let interval = 1000; | |
function delay(duration) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), duration); | |
}); | |
} | |
fetch(`https://discordapp.com/api/v6/guilds/${guild}/messages/search?author_id=${author}`, {headers}) | |
.then(response => response.json()) | |
.then(json => { | |
Array.from(json.messages).map(message => { | |
message.forEach(function(item) { | |
if(item.hit === true) { | |
delay(clock += interval).then(() => { fetch(`https://discordapp.com/api/v6/channels/${item.channel_id}/messages/${item.id}`, { headers, method: 'DELETE' }) }); | |
} | |
}); | |
}); | |
if (json.total_results > 0) { delay(clock += interval).then(() => { deleteMessage(); }); } | |
}); | |
} | |
deleteMesssage() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Status on 3/19/2021: WORKING
Javascript used to delete all messages within a certain discord server by utilizing the existing search function.
Please do not change the interval too low, as it might trigger a Discord ban, more information please visit: https://discordapp.com/developers/docs/topics/rate-limits
How to:
the script will now start to delete all your messages, it might take a while for the process.