Advertisement
Guest User

Delete all discord messages from DM or server automatically

a guest
Nov 4th, 2018
1,880
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // IMcPwn/delete-all-messages.js forked from niahoo/delete-all-messages.js
  2. // Turn on Developer Mode under User Settings > Appearance > Developer Mode (at the bottom)
  3. // Then open the channel you wish to delete all of the messages (could be a DM) and click the three dots on the far right.
  4. // Click "Copy ID" and paste that instead of LAST_MESSAGE_ID.
  5. // Copy / paste the below script into the JavaScript console.
  6. // If you're in a DM you will receive a 403 error for every message the other user sent (you don't have permission to delete their messages).
  7.  
  8. var before = 'LAST_MESSAGE_ID';
  9. clearMessages = function(){
  10.     const authToken = document.body.appendChild(document.createElement`iframe`).contentWindow.localStorage.token.replace(/"/g, "");
  11.     const channel = window.location.href.split('/').pop();
  12.     const baseURL = `https://discordapp.com/api/channels/${channel}/messages`;
  13.     const headers = {"Authorization": authToken };
  14.  
  15.     let clock = 0;
  16.     let interval = 500;
  17.  
  18.     function delay(duration) {
  19.         return new Promise((resolve, reject) => {
  20.             setTimeout(() => resolve(), duration);
  21.         });
  22.     }
  23.  
  24.     fetch(baseURL + '?before=' + before + '&limit=100', {headers})
  25.         .then(resp => resp.json())
  26.         .then(messages => {
  27.         return Promise.all(messages.map((message) => {
  28.             before = message.id;
  29.             return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
  30.         }));
  31.     }).then(() => clearMessages());
  32. }
  33. clearMessages();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement