Created
January 31, 2020 15:33
-
-
Save Mlocik97/9bba36972c29ea741b7016437510a3ce to your computer and use it in GitHub Desktop.
discord delete messages
This file contains hidden or 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() { | |
| const Authorization = ''; // past here AuthKey | |
| const GET = { headers: { Authorization }, method: 'GET' }; | |
| const DELETE = { headers: { Authorization }, method: 'DELETE'}; | |
| const sleep = ms => new Promise(resolve => setTimeout(resolve, ms)); | |
| const me = await fetch('/api/v6/users/@me', GET) | |
| .then(r => r.json()) | |
| .then(d => d.id); | |
| const url = window.location.pathname.replace(/^.+\//, '/api/v6/channels/') | |
| let msgs = await fetch(`${url}/messages?limit=1`, GET).then(r => r.json()); | |
| while (msgs.length > 0) { | |
| const ids = msgs.filter(m => m.author.id == me).map(m => m.id); | |
| for (let i = 0; i < ids.length; i++) { | |
| console.log('Deleting message', ids[i]); | |
| const r = await fetch(`${url}/messages/${ids[i]}`, DELETE); | |
| if (r.status === 429) { | |
| await r.json().then(r => sleep(r.retry_after)) | |
| i--; | |
| } | |
| } | |
| msgs = await fetch( | |
| `${url}/messages?limit=100&before=${msgs[msgs.length-1].id}`, GET) | |
| .then(r => r.json()); | |
| } | |
| console.log('Done'); | |
| })(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment