Skip to content

Instantly share code, notes, and snippets.

@1Conan
Created March 9, 2019 16:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 1Conan/f0ed9816ce3100166c66ac8acd682b95 to your computer and use it in GitHub Desktop.
Save 1Conan/f0ed9816ce3100166c66ac8acd682b95 to your computer and use it in GitHub Desktop.
const fetch = require('node-fetch');
// Config
const authToken = '';
const userId = '';
const guildId = '';
const headers = {
Authorization: authToken
};
const loadMessages = (gid, uid) => fetch(`https://canary.discordapp.com/api/v6/guilds/${gid}/messages/search?author_id=${uid}`, { headers }).then(r => r.json())
const delay = (duration) => new Promise((resolve, reject) => setTimeout(resolve, duration))
async function deleteMsgs() {
const { messages, total_results } = await loadMessages(guildId, userId)
console.log(`Found ${total_results} messages`)
for (const message of messages) {
const msg = message.find(x => x.author.id === userId);
if (msg.author.id !== userId) continue;
console.log(`Deleting ${msg.id}`)
await fetch(`https://discordapp.com/api/v6/channels/${msg.channel_id}/messages/${msg.id}`, { headers, method: 'DELETE', })
// Rate limit shit
await delay(500)
}
console.log(`Done clearing ${messages.length} messages.`)
if (total_results > 25) deleteMsgs();
}
deleteMsgs();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment