Skip to content

Instantly share code, notes, and snippets.

@FirstWhack
Last active March 5, 2021 04:42
Show Gist options
  • Save FirstWhack/9f2b305a1ea0d15c408c4c6b356d9b44 to your computer and use it in GitHub Desktop.
Save FirstWhack/9f2b305a1ea0d15c408c4c6b356d9b44 to your computer and use it in GitHub Desktop.
Discord Mass Ban from List
// --- USAGE ---
// - Populate `IDS` list (make a JSON array of the IDs to ban)
let IDS = ['8165...', '8165...', '8165...', '8165...', '8165...'];
// - Populate SERVER_ID
let SERVER_ID = '1234567890';
// - Login to discord web client
// - Run script in F12 console (snippets, or just paste directly into Console)
// --- END USAGE---
// --- EXAMPLE OUTPUT ---
// Starting to check 12 IDs
// Checked 12 - Banned 0 - Already Banned 12 from list
// --- END EXAMPLE OUTPUT ---
// funny discord tries to hide localStorage...
window.localStorage = window.localStorage || getLocalStoragePropertyDescriptor().get.call(window);
let token = localStorage.getItem('token')?.split('"')[1];
doMassBan(IDS, token);
function doMassBan(ids = [], token = '') {
let added = 0, checked = 0, iterator = ids?.[Symbol.iterator]();
if (ids && ids.length && token && iterator) {
new Promise(resolve => {
console.info(`Starting to check ${ids.length} IDs`)
itcheckBans().finally(() => resolve({ added, checked }));
}).then(({ added, checked }) => console.info(`Checked ${checked} - `, `Banned ${added} - `, `Already Banned ${checked - added} from list`))
} else {
throw new Error('Token or id list error');
}
function doBan(id = '') {
return fetch(`https://discord.com/api/v8/guilds/${SERVER_ID}/bans/${id}`, {
'headers': {
'authorization': token,
},
'method': 'PUT',
'credentials': 'include'
}).then(() => {
added++;
console.info(`ban added for ${id}`)
});
}
function itcheckBans() {
const next = iterator.next();
return next.done ? Promise.resolve() : fetch(`https://discord.com/api/v8/guilds/${SERVER_ID}/bans/${next.value}`, {
'headers': {
'authorization': token,
'cache-control': 'no-cache',
},
'method': 'GET',
'credentials': 'include'
}).then(resp => {
checked++;
if (!resp.ok) {
if (resp.status === 404) return doBan(next.value);
else console.debug(`Something weird happened on ${next.value} - got ${resp.status}`, resp);
} else {
return;
}
}).then(() => {
return itcheckBans();
})
}
}
function getLocalStoragePropertyDescriptor() {
const iframe = document.createElement('iframe');
document.head.append(iframe);
const pd = Object.getOwnPropertyDescriptor(iframe.contentWindow, 'localStorage');
iframe.remove();
return pd;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment