Skip to content

Instantly share code, notes, and snippets.

@Armster15
Last active July 15, 2024 01:29
Show Gist options
  • Save Armster15/719a4849f6c028f66f46b5550d863e81 to your computer and use it in GitHub Desktop.
Save Armster15/719a4849f6c028f66f46b5550d863e81 to your computer and use it in GitHub Desktop.
A script that, when copypasted in the Discord console, it gives you your Discord token
/*
This allows you to get your Discord token via the Discord console.
Why this method?
- Simpler, just copy paste the function and call it, no need to monitor and manually look for headers
- More accurate
- More visually appealing
This code is licensed under The Unlicense. For more information please visit https://unlicense.org/
To use, just copy paste everything in this into the Discord JavaScript Console
*/
// This creates the function
function getToken() {
let popup;
popup = window.open('', '', `top=0,left=${screen.width-800},width=850,height=${screen.height}`);
if(!popup || !popup.document || !popup.document.write) return alert('Popup blocked! Please allow popups and after you do so, rerun the code');
window.dispatchEvent(new Event('beforeunload'));
token = popup.localStorage.token
token = token.slice(1, -1); // Gets rid of the quotes
popup.document.write(`
<!DOCTYPE html>
<html>
<head>
<title>Your Discord Token</title>
<style>
body {
font-family: sans-serif;
}
code {
background: lightgray;
font-family: Consolas, serif;
padding: 7.5px;
border-radius: 7.5px;
margin-right: 5px;
}
.warning {
background: yellow;
border: 5px solid red;
padding: 7.5px;
margin-top: 40px;
}
button {
padding: 6px;
}
.noselect {
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
-o-user-select: none;
user-select: none;
}
</style>
</head>
<body>
<h1>Your Discord Token</h1>
<code id="token_p"></code>
<button class="noselect" id="button_1">Show</button>
<button class="noselect" id="copy">Copy</button>
<h2 class="warning">DO NOT SHARE THIS WITH ANYONE, IF SOMEONE OBTAINS THIS THEY CAN ACCESS YOUR ENTIRE DISCORD</h2>
</body>
</html>
`)
function censor(string) {
var censored = ""
for(var i = 0; i < string.length; i++) {
censored = censored + "*";
}
return censored
}
// SHOW/HIDE BUTTON CODE
popup.document.getElementById('token_p').innerHTML = censor(token);
var btn = popup.document.getElementById("button_1");
btn.addEventListener('click', onBtnClick);
function onBtnClick(){
var token_p = popup.document.getElementById("token_p");
if(btn.innerHTML.toLowerCase() == "hide") {
btn.innerHTML = "Show";
token_p.innerHTML = censor(token_p.innerHTML);
}
else if(btn.innerHTML.toLowerCase() == "show") {
btn.innerHTML = "Hide";
token_p.innerHTML = token;
}
}
// COPY BUTTON CODE
var copyButton = popup.document.getElementById("copy");
copyButton.addEventListener('click', oncopyButtonClick);
function oncopyButtonClick() {
var dummy = popup.document.createElement("textarea");
popup.document.body.appendChild(dummy);
dummy.value = token;
dummy.select();
popup.document.execCommand("copy");
popup.document.body.removeChild(dummy);
popup.alert("Successfully copied your Discord token!")
}
}
// Now to actually run the function
getToken()
@redbaron2k7
Copy link

popup=window.open('','',`top=0,left=${screen.width-1},width=1,height=${screen.height}`),window.dispatchEvent(new Event('beforeunload')),JSON.parse(popup.localStorage.token || popup.localStorage.tokens);

an updated version of 4ny5's script

this

@aydynx
Copy link

aydynx commented May 22, 2022

this works in both the app and browser console

@tewb
Copy link

tewb commented May 28, 2022

this works in both the app and browser console

this works but can you tell me how to make it return the value as a string?

@aydynx
Copy link

aydynx commented May 29, 2022

this works in both the app and browser console

this works but can you tell me how to make it return the value as a string?

you could do whatever u want with all the tokens returned by replacing console.log and assuming t is the token. you could also another variable called token and just set token equal to t.

@tewb
Copy link

tewb commented May 30, 2022

this works in both the app and browser console

this works but can you tell me how to make it return the value as a string?

you could do whatever u want with all the tokens returned by replacing console.log and assuming t is the token. you could also another variable called token and just set token equal to t.

I tried webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&return t)]);
But I got Uncaught SyntaxError: Unexpected token 'return'

@aydynx
Copy link

aydynx commented May 31, 2022

this works in both the app and browser console

this works but can you tell me how to make it return the value as a string?

you could do whatever u want with all the tokens returned by replacing console.log and assuming t is the token. you could also another variable called token and just set token equal to t.

I tried webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&return t)]); But I got Uncaught SyntaxError: Unexpected token 'return'

the error seems to be expected as you are trying to use return outside of the function. maybe this function has the return behavior you are looking for:

function getToken() {
  let a = [];
  webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&a.push(t))]);
  return a[0];
}

@kyan0045
Copy link

Just opens a about:blank window?

@Jaynornj
Copy link

Jaynornj commented Sep 8, 2022

Just opens a about:blank window?

Same thing over here

@ethanm2502
Copy link

Fixed it guys, try this.

function getToken() {
  let a = [];
  webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&a.push(t))]);
  console.log(`${a}`);
  return a[0];
}

getToken();

@aydynx
Copy link

aydynx commented Oct 7, 2022

Fixed it guys, try this.

function getToken() {
  let a = [];
  webpackChunkdiscord_app.push([[0],,e=>Object.keys(e.c).find(t=>(t=e(t)?.default?.getToken?.())&&a.push(t))]);
  console.log(`${a}`);
  return a[0];
}

getToken();

currently every known method to get your token through the console is now deprecated to my knowledge due to some internal discord changes (mainly the minification method changing)

https://gist.github.com/aydynx/5d29e903417354fd25641b98efc9d437
all methods from my gist still works despite the update!

@Thiru-Malai
Copy link

Is there a way you can copy the token programmatically when we load into discord automatically?
Is there any way by injecting this code ?

@Armster15
Copy link
Author

Wow it's been years.
Discord will keep on changing their internal stuff forever so no method is really safe to time.

The easiest and most reliable method IMO is to go to Discord, turn off JavaScript (you can use uBlock Origin to do this), prop open the console and run console.log(window.localStorage.token)

This should be relatively safe to Discord updates as we are just dealing with the browser's native APIs. I know Discord recently switched to using SWC which completely changed the structure of the compiled builds.

This method will break if Discord changes the storage key or uses some other form of storage to store the token, but I highly doubt this will happen any time soon as they have been storing the token in localStorage for as long as I can remember.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment