Skip to content

Instantly share code, notes, and snippets.

@Infinitay
Forked from g1ver/discordnames.js
Created June 13, 2023 10:02
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 Infinitay/4224e0982862fe0db8196c6e6914e6a6 to your computer and use it in GitHub Desktop.
Save Infinitay/4224e0982862fe0db8196c6e6914e6a6 to your computer and use it in GitHub Desktop.
discord name trying script
namelist = [] // names here
async function processNames() {
for (const name of namelist) {
try {
const res = await makeRequest(name);
if (res.ok) {
console.log(`Username ${name} is available.`);
break;
}
} catch (error) {
console.error(`An error occurred while processing username ${name}:`, error);
}
}
}
async function makeRequest(name) {
const res = await fetch("https://discord.com/api/v9/users/@me", {
// config, get from network tab of devtools after trying to change name
});
if (res.ok) {
return res;
} else if (res.status === 429) {
const retryAfter = res.headers.get('Retry-After');
const delay = retryAfter ? parseInt(retryAfter) * 1000 : 1000; // default delay of 1 second
console.log(`Rate limit exceeded. Retrying after ${delay / 1000} seconds.`);
await sleep(delay); // wait for the specified delay before retrying
return makeRequest(name); // retry the request
} else {
throw new Error(`Request failed with status ${res.status}`);
}
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
processNames();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment