Skip to content

Instantly share code, notes, and snippets.

@max1mde
Last active December 8, 2024 22:26
Show Gist options
  • Save max1mde/437532d7b08f7e54c2bb7147828ab0e7 to your computer and use it in GitHub Desktop.
Save max1mde/437532d7b08f7e54c2bb7147828ab0e7 to your computer and use it in GitHub Desktop.
Discord friend invite link generator code - Console script (Tested 12/9/2024)

Discord Friend Invite Generator

This script generates a friend invite link for Discord by recursively searching for the createFriendInvite method within Discord web. This method is up to date and works without any custom Discord clients

Last time tested: 12/9/2024

Note

This method is designed to be more resilient to updates, as it dynamically searches for the createFriendInvite function instead of relying on a hardcoded, currently working method that may become outdated.

image

Usage

  1. Open Discord in your browser https://app.discord.com/
  2. Open the Developer Tools (usually by pressing F12 or Ctrl+Shift+I). Or in Chrome if no hotkey works: Hambuger menu at the top right -> "More tools" -> "Developer tools"
  3. Navigate to the Console tab.
  4. Copy and paste the script below into the console and press Enter.
  5. You should now see an output like this:

image

const deepSearchForMethod = (obj, methodName, path = '', visited = new Set(), maxDepth = 10, depth = 0) => {
if (depth > maxDepth || visited.has(obj)) {
return null;
}
visited.add(obj);
for (let key in obj) {
if (obj[key] && typeof obj[key] === 'object') {
if (obj[key][methodName]) {
console.log(`Found ${methodName} at path: ${path}.${key}`);
return obj[key][methodName];
}
const result = deepSearchForMethod(obj[key], methodName, `${path}.${key}`, visited, maxDepth, depth + 1);
if (result) return result;
}
}
return null;
};
const searchForFriendInviteMethod = async () => {
webpackChunkdiscord_app.push([
[Symbol()], {},
async r => {
if (r) {
const methodName = 'createFriendInvite';
const foundMethod = deepSearchForMethod(r, methodName);
if (foundMethod) {
try {
const invite = await foundMethod();
console.log('Your friend invite link: https://discord.gg/' + invite.code);
} catch (e) {
console.error(`Error creating friend invite:`, e);
}
} else {
console.error(`${methodName} method not found.`);
}
} else {
console.error("r is undefined or null.");
}
}
]);
!!webpackChunkdiscord_app.pop();
};
searchForFriendInviteMethod();
const deepSearchForMethod=(e,r,t="",n=new Set,o=10,i=0)=>{if(i>o||n.has(e))return null;for(let d in n.add(e),e)if(e[d]&&"object"==typeof e[d]){if(e[d][r])return console.log(`Found ${r} at path: ${t}.${d}`),e[d][r];let a=deepSearchForMethod(e[d],r,`${t}.${d}`,n,o,i+1);if(a)return a}return null},searchForFriendInviteMethod=async()=>{webpackChunkdiscord_app.push([[Symbol()],{},async e=>{if(e){let r="createFriendInvite",t=deepSearchForMethod(e,r);if(t)try{let n=await t();console.log("Your friend invite link: https://discord.gg/"+n.code)}catch(o){console.error("Error creating friend invite:",o)}else console.error(`${r} method not found.`)}else console.error("r is undefined or null.")}]),webpackChunkdiscord_app.pop()};searchForFriendInviteMethod();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment