ChrisEric1.GitHub.io icon indicating copy to clipboard operation
ChrisEric1.GitHub.io copied to clipboard

Question regarding logging in

Open madkarmaa opened this issue 1 year ago • 8 comments

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.

madkarmaa avatar Mar 04 '24 07:03 madkarmaa

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.

CE1CECL avatar Mar 04 '24 12:03 CE1CECL

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

madkarmaa avatar Mar 04 '24 14:03 madkarmaa

bf41583d33a683460193.js.zip This is what I did in the new branch to patch for a newer client last year.

CE1CECL avatar Mar 06 '24 13:03 CE1CECL

I don't even know what to look for in a 22mb file

madkarmaa avatar Mar 06 '24 20:03 madkarmaa

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

CE1CECL avatar Mar 08 '24 13:03 CE1CECL

ok, how can I implement these changes at runtime? as I said I'm trying to make it work on discord.com

madkarmaa avatar Mar 10 '24 16:03 madkarmaa

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

CE1CECL avatar Mar 23 '24 14:03 CE1CECL

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 "

CE1CECL avatar Mar 23 '24 15:03 CE1CECL

image This happens all the time and every time I enter the page

FF1Gq avatar May 23 '24 00:05 FF1Gq

image This happens all the time and every time I enter the page

Apologize for my long delay, but is the extension installed in your browser? Discord made the gateway also CORS enabled so before you couldn't load messages, but you can't load anything now, it was shown in a different issue some time ago. If it is installed, do CTRL + SHIFT + I and open Console and show me any errors.

CE1CECL avatar Jun 02 '24 17:06 CE1CECL

Closing due to inactivity.

CE1CECL avatar Jul 03 '24 20:07 CE1CECL