Closed madkarmaa closed 2 months ago
How does the website work? I'm trying to create a JavaScript code snippet to allow me to login as a bot on the official discord.com website. While I can easily set the bot token in the localStorage, I cannot connect because of the websocket missing the bot intents. I can't find the code about the /login route in this repository, but I might just be blind.
If you are missing intents, this website is old enough to not need them since its using API v6 (v7 works too) and doesn't need them. v8+ does. You would have to patch the gateway code to use intents somewhere in the assets.
I have a snippet which works perfectly, but I don't know how to apply it to discord.com
const ws = new WebSocket('wss://gateway.discord.gg/?v=9&encoding=json');
let interval = 0;
const token = 'BOT TOKEN HERE';
const payload = {
op: 2,
d: {
token: token,
intents: 3276799,
properties: {
$os: 'linux',
$browser: 'chrome',
$device: 'chrome',
},
compress: false,
},
};
let lastS = -1;
ws.addEventListener('open', () => {
console.log('Connected to Discord Gateway');
ws.send(JSON.stringify(payload));
});
ws.addEventListener('message', (e) => {
const payload = JSON.parse(e.data);
const { t, d, op, s } = payload;
console.log(`[dispatch event: ${t} - seq: ${s}] opcode:`, op, `response:`, d);
if (s) lastS = s;
if (op === 10) {
const { heartbeat_interval } = d;
let interval = setInterval(() => {
ws.send(
JSON.stringify({
op: 1,
d: lastS === -1 ? null : lastS,
})
);
}, heartbeat_interval);
}
});
this uses vanilla js code to connect to a bot account and listen for events. a normal user uses a websocket as well, but the format is way different
!(function () {
if (null != window.WebSocket) {
if (
(function (n) {
try {
var e = localStorage.getItem(n);
return null == e ? null : JSON.parse(e);
} catch (n) {
return null;
}
})('token') &&
!window.__OVERLAY__
) {
var n = null != window.DiscordNative || null != window.require ? 'etf' : 'json',
e =
window.GLOBAL_ENV.GATEWAY_ENDPOINT +
'/?encoding=' +
n +
'&v=' +
window.GLOBAL_ENV.API_VERSION +
'&compress=zlib-stream';
console.log('[FAST CONNECT] connecting to: ' + e);
var o = new WebSocket(e);
o.binaryType = 'arraybuffer';
var t = Date.now(),
i = { open: !1, identify: !1, gateway: e, messages: [] };
(o.onopen = function () {
console.log('[FAST CONNECT] connected in ' + (Date.now() - t) + 'ms'), (i.open = !0);
}),
(o.onclose = o.onerror =
function () {
window._ws = null;
}),
(o.onmessage = function (n) {
i.messages.push(n);
}),
(window._ws = { ws: o, state: i });
}
}
})();
(got from discord.com)
as you can see, window._ws
is the websocket, and I need to somehow overwrite it before it connects
bf41583d33a683460193.js.zip This is what I did in the new branch to patch for a newer client last year.
I don't even know what to look for in a 22mb file
I don't even know what to look for in a 22mb file
Look at the DIFF file, it has what is needed to log in to discord as a bot for newer clients, the other files are for reference. You need to also (as shown in diff) change bot=true to make it false by force
ok, how can I implement these changes at runtime? as I said I'm trying to make it work on discord.com
ok, how can I implement these changes at runtime? as I said I'm trying to make it work on discord.com
How are you going to inject it? Via F12 console, extensions, what? You also need to load the patches in time, before discord client logs off the bot to the login screen, because if it sees "bot == true" then it will, unless patched
ok, how can I implement these changes at runtime? as I said I'm trying to make it work on discord.com
How are you going to inject it? Via F12 console, extensions, what? You also need to load the patches in time, before discord client logs off the bot to the login screen, because if it sees "bot == true" then it will, unless patched
If you look at this sites source, the asset is injected before loading the page (https://github.com/ChrisEric1/ChrisEric1.GitHub.io/blob/7178544ee4d848d90c3943a88062476505965eb8/404.html#L48) usually the assets would be defined differently (such as https://github.com/ChrisEric1/ChrisEric1.GitHub.io/blob/7178544ee4d848d90c3943a88062476505965eb8/LCP.DBC.html#L48 " Githubissues.
How does the website work? I'm trying to create a JavaScript code snippet to allow me to login as a bot on the official discord.com website. While I can easily set the bot token in the localStorage, I cannot connect because of the websocket missing the bot intents. I can't find the code about the /login route in this repository, but I might just be blind.