Skip to content

Instantly share code, notes, and snippets.

@jsoctocat
Last active March 19, 2021 19:08
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 jsoctocat/586feb9e530e61e6f499f7b7773b4df3 to your computer and use it in GitHub Desktop.
Save jsoctocat/586feb9e530e61e6f499f7b7773b4df3 to your computer and use it in GitHub Desktop.
Delete all messages in a particular discord server
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()
@jsoctocat
Copy link
Author

jsoctocat commented May 24, 2019

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:

  1. go to https://discordapp.com/
  2. login to your account
  3. go to the server you wish to delete all your messages in
  4. press ctrl+shift+i (chrome) to open up the developer console
  5. go to the Network section within the developer console,
  6. go to the search bar and search "from: your-username" (while the developer console is open)
  7. under Name (within the network section) look for "search?author_id=xxx", click that
  8. look at Request Headers
  9. look for :path: ":path: /api/v6/guilds/x/messages/search?author_id=xx ", x is the SERVER_ID, xx is your YOUR_ID_HERE
  10. look for authorization, replace it with TOKEN HERE
  11. now copy and paste the whole code to the Console section within the developer tool and hit enter.

the script will now start to delete all your messages, it might take a while for the process.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment