Advertisement
Guest User

Discord Del DM Script

a guest
Feb 18th, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.53 KB | None | 0 0
  1. • The channel id is the YYYYYYYYY part here :
  2. https://discordapp.com/channels/XXXXXXXX/YYYYYYYYY
  3.  
  4. ```js
  5. // VARIABLES
  6. var channelid = '_________________';
  7. var authorization = '_____________________________________';
  8.  
  9. // FUNCTIONS
  10. Object.size = function(obj) {
  11. var size = 0, key;
  12. for (key in obj) {
  13. if (obj.hasOwnProperty(key)) size++;
  14. }
  15. return size;
  16. };
  17.  
  18. function sleep(ms) {
  19. return new Promise(resolve => setTimeout(resolve, ms));
  20. }
  21.  
  22. function deleteOneMessage(id) {
  23. var xhr = new XMLHttpRequest();
  24. xhr.open("DELETE", "https://discordapp.com/api/v6/channels/"+channelid+"/messages/"+id, true);
  25. xhr.setRequestHeader("authorization", authorization);
  26. xhr.onreadystatechange = function() {
  27. if (xhr.readyState == 4) {
  28. console.log("deleted: "+id+" "+xhr.status);
  29. }
  30. }
  31. xhr.send();
  32. }
  33.  
  34. async function deleteAllMessages(ids) {
  35. for (var i=0; i<ids.length; i++) {
  36. deleteOneMessage(ids[i]);
  37. await sleep(200);
  38. }
  39. getId();
  40. }
  41.  
  42. function getId() {
  43. var xhr = new XMLHttpRequest();
  44. xhr.open("GET", "https://discordapp.com/api/v6/channels/"+channelid+"/messages?limit=100", true);
  45. xhr.setRequestHeader("authorization", authorization);
  46. xhr.onreadystatechange = function() {
  47. if (xhr.readyState == 4 && (xhr.status == 200 || xhr.status == 0)) {
  48. var obj = JSON.parse(xhr.responseText);
  49. var size = Object.size(obj);
  50.  
  51. var ids = new Array();
  52. for (var i=0; i<size; i++) {
  53. ids[i] = obj[i].id;
  54. }
  55.  
  56. deleteAllMessages(ids);
  57. }
  58. }
  59. xhr.send();
  60. }
  61.  
  62. getId();
  63. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement