Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. //Works as of 1st of Dec, 2018
  2. var lastmsg = "message" // Copy the ID of the newest message you want to be cleared
  3. var youruser = "username" // Your username.
  4. clearMessages = function(){
  5. const authToken = "token"
  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 = "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. MAKE SURE ALL OF THE IDS ARE GIVEN A STRINGS, NOT LITERAL NUMBERS!
  14. OTHERWISE, JAVASCRIPT WILL ROUND THEM A LITTLE, CAUSING STUPID FUCKIN 404 ERRORS
  15. */
  16. const baseURL = "https://discordapp.com/api/channels/" + channel + "/messages";
  17. const headers = {"Authorization": authToken };
  18.  
  19. let clock = 0;
  20. let interval = 500;
  21.  
  22. function delay(duration) {
  23. return new Promise((resolve, reject) => {
  24. setTimeout(() => resolve(), duration);
  25. });
  26. }
  27.  
  28. fetch(baseURL + "?before=" + lastmsg, {headers, method: 'GET'})// Fetch the message data from discord
  29. .then(resp => resp.json()) // Make it into a json
  30. .then(messages => { // Call that json "messages" and do this function with it as the parameter:
  31. if(typeof messages == "undefined")
  32. {
  33. console.log("Yeah, you fucked one of your IDs up, son.");
  34. throw new Error();
  35. }
  36. return Promise.all(messages.map(
  37. (message) => { // Call this function for all messages we got
  38. lastmsg = message.id
  39. if(message.author.username == youruser)
  40. {
  41. return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
  42. }
  43. else
  44. {
  45. //console.log("Found a message written by someone else!");
  46. return
  47. }
  48. }));
  49. }).then(() => clearMessages()); // And once we've deleted all the messages we can see, ask for more!
  50. }
  51. clearMessages();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement