Skip to content

Instantly share code, notes, and snippets.

@cookieguru
Created September 8, 2025 02:01
Show Gist options
  • Select an option

  • Save cookieguru/87c21a3aa8baa791a46550b3b378206f to your computer and use it in GitHub Desktop.

Select an option

Save cookieguru/87c21a3aa8baa791a46550b3b378206f to your computer and use it in GitHub Desktop.
Deletes all messages in the current channel on a Discord server
// leave browser tab open while channel is being purged
let sleep = (ms) => new Promise(resolve => setTimeout(resolve, ms));
let deleteMessage = async(channel, message) => {
const response = await fetch(`https://discord.com/api/v9/channels/${channel}/messages/${message}`, {
method: 'DELETE',
headers: {
'Authorization': 'find token from another request' //TODO: change me
},
});
if(response.status === 429) {
const retryAfter = response.headers.get('retry-after');
console.log(`Rate limit hit, retrying after ${retryAfter} seconds...`);
const waitTime = parseFloat(retryAfter) * 1000;
await sleep(waitTime);
return deleteMessage(channel, message);
}
return response;
};
let deleteAllMessages = async() => {
const messageItems = Array.from(document.querySelectorAll('li[id^="chat-messages-"]')).reverse();
for(const li of messageItems) {
const match = li.id.match(/^chat-messages-(\d+)-(\d+)$/);
const channel = match[1];
const message = match[2];
await deleteMessage(channel, message);
await sleep(750);
}
deleteAllMessages();
};
deleteAllMessages();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment