Created
March 9, 2019 16:40
-
-
Save 1Conan/f0ed9816ce3100166c66ac8acd682b95 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
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