Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Works as of 1st of Dec, 2018
- var lastmsg = "message" // Copy the ID of the newest message you want to be cleared
- var youruser = "username" // Your username.
- clearMessages = function(){
- const authToken = "token"
- // ^ The above is your token value, not fingerprint
- // To get it, open up your browser's dev stuff, go to Applications, and then open up local storage
- // when you refresh the page, a value for token will appear, but only for a few seconds.
- // You have to ninja a CTRL+C of that value so you can put it here.
- const channel = "channel";
- // ^ This you can get from the URL that shows up in the browser version of discord; it's the ~18-digit number in it.
- /*
- MAKE SURE ALL OF THE IDS ARE GIVEN A STRINGS, NOT LITERAL NUMBERS!
- OTHERWISE, JAVASCRIPT WILL ROUND THEM A LITTLE, CAUSING STUPID FUCKIN 404 ERRORS
- */
- const baseURL = "https://discordapp.com/api/channels/" + channel + "/messages";
- const headers = {"Authorization": authToken };
- let clock = 0;
- let interval = 500;
- function delay(duration) {
- return new Promise((resolve, reject) => {
- setTimeout(() => resolve(), duration);
- });
- }
- fetch(baseURL + "?before=" + lastmsg, {headers, method: 'GET'})// Fetch the message data from discord
- .then(resp => resp.json()) // Make it into a json
- .then(messages => { // Call that json "messages" and do this function with it as the parameter:
- if(typeof messages == "undefined")
- {
- console.log("Yeah, you fucked one of your IDs up, son.");
- throw new Error();
- }
- return Promise.all(messages.map(
- (message) => { // Call this function for all messages we got
- lastmsg = message.id
- if(message.author.username == youruser)
- {
- return delay(clock += interval).then(() => fetch(`${baseURL}/${message.id}`, {headers, method: 'DELETE'}));
- }
- else
- {
- //console.log("Found a message written by someone else!");
- return
- }
- }));
- }).then(() => clearMessages()); // And once we've deleted all the messages we can see, ask for more!
- }
- clearMessages();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement