Last active
July 28, 2019 17:28
-
-
Save oddmario/e2ba1c452eb4e35fe3063e6f16cba966 to your computer and use it in GitHub Desktop.
Delete all messages in Discord channel/DM
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
function sleep(milliseconds) { | |
var start = new Date().getTime(); | |
while (true) { | |
if ((new Date().getTime() - start) > milliseconds) { | |
break; | |
} | |
} | |
} | |
function deleteMessages() { | |
const authorId = "your discord ID here"; | |
const channelId = "channel ID here"; | |
const deleteAfter = "search?author_id=" + authorId + "&min_id=000000000000000000"; | |
const baseURL = "https://discordapp.com/api/v6/channels/" + channelId + "/messages/"; | |
const authToken = "your discord token here"; | |
const headers = { | |
"Authorization": authToken | |
}; | |
try { | |
fetch(baseURL + deleteAfter, { | |
headers | |
}) | |
.then(resp => resp.json()) | |
.then(result => { | |
console.log("There are " + result.total_results + " messages left to delete."); | |
if (result.total_results == 0) { | |
alert("All the messages got deleted. \nPlease refresh the page before pressing 'OK'."); | |
} | |
result.messages.forEach(function(element) { | |
element.forEach(function(message) { | |
if (message.author.id == authorId && message.hit == true && message.id && message.type == 0 && "content" in message && !message.call) { | |
console.log("Deleting message with Id #" + message.id); | |
console.log(baseURL + message.id); | |
fetch(baseURL + message.id, { | |
headers, | |
method: "DELETE" | |
}); | |
} | |
}); | |
sleep(100); | |
}); | |
}) | |
.then(() => deleteMessages()); | |
} catch (e) { | |
//ignore errors | |
console.log(e) | |
} | |
} | |
deleteMessages(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment