Created
April 22, 2019 07:35
-
-
Save BrianHung/34e2c4744096c175c6fde2438c9e6a08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function clearMessages() { | |
const server = ""; // server id number | |
const author = ""; // user id number | |
const authToken = ""; // authToken - look inside a network packet | |
const headers = { 'Authorization': authToken, 'Content-Type': 'application/json' }; | |
const baseURL = `https://discordapp.com/api/v6/channels`; | |
let searchURL = `https://discordapp.com/api/v6/guilds/${server}/messages/search?author_id=${author}`; | |
if (typeof channel !== 'undefined') searchURL = searchURL + `&channel_id=${channel}`; | |
let clock = 0; | |
let interval = 500; | |
function delay(duration) { | |
return new Promise((resolve, reject) => { | |
setTimeout(() => resolve(), duration); | |
}); | |
} | |
const response = await fetch(searchURL, {headers}); | |
const json = await response.json(); | |
console.log("There are " + json.total_results + " messages left to delete."); | |
await Array.from(json.messages).map(message => { | |
message.forEach(async function(item) { | |
if(item.hit == true) { | |
await delay(clock += interval); | |
await fetch(`${baseURL}/${item.channel_id}/messages/${item.id}`, { headers, method: 'DELETE' }); | |
} | |
}); | |
}); | |
if (json.total_results > 0) { | |
delay(clock += interval).then(() => { clearMessages(); }); | |
} else { | |
console.log("Finished deleting messages") | |
}; | |
} | |
clearMessages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment