Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. //Works as of 1st of Dec, 2018
  2. var lastmsg = "" // Copy the ID of the newest message you want to be cleared
  3. var youruser = "" // Your username.
  4. clearMessages = function(){
  5. const authToken = ""
  6. // ^ The above is your token value, not fingerprint
  7. // To get it, open up your browser's dev stuff, go to Applications, and then open up local storage
  8. // when you refresh the page, a value for token will appear, but only for a few seconds.
  9. // You have to ninja a CTRL+C of that value so you can put it here.
  10. const channel = "";
  11. // ^ This you can get from the URL that shows up in the browser version of discord; it's the ~18-digit number in it.
  12.  
  13. /*
  14. MAKE SURE ALL OF THE IDS ARE GIVEN A STRINGS, NOT LITERAL NUMBERS!
  15. OTHERWISE, JAVASCRIPT WILL ROUND THEM A LITTLE, CAUSING STUPID FUCKIN 404 ERRORS
  16. */
  17. const baseURL = "https://discordapp.com/api/channels/" + channel + "/messages";
  18. const headers = {"Authorization": authToken };
  19.  
  20. let clock = 0;
  21. let interval = 500;
  22.  
  23. function delay(duration) {
  24. return new Promise((resolve, reject) => {
  25. setTimeout(() => resolve(), duration);
  26. });
  27. }
  28.  
  29. fetch(baseURL + "?before=" + lastmsg, {headers, method: 'GET'})// Fetch the message data from discord
  30. .then(resp => resp.json()) // Make it into a json
  31. .then(messages => { // Call that json "messages" and do this function with it as the parameter:
  32. if(typeof messages == "undefined")
  33. {
  34. console.log("Yeah, you fucked one of your IDs up, son.");
  35. throw new Error();
  36. }
  37. return Promise.all(messages.map(
  38. (message) => { // Call this function for all messages we got
  39. lastmsg = message.id
  40. if(message.author.username == youruser)
  41. {
  42. return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
  43. }
  44. else
  45. {
  46. //console.log("Found a message written by someone else!");
  47. return
  48. }
  49. }));
  50. }).then(() => clearMessages()); // And once we've deleted all the messages we can see, ask for more!
  51. }
  52. clearMessages();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement