Giter Club home page Giter Club logo

Comments (10)

CE1CECL avatar CE1CECL commented on June 9, 2024

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.

from chriseric1.github.io.

madkarmaa avatar madkarmaa commented on June 9, 2024

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

from chriseric1.github.io.

CE1CECL avatar CE1CECL commented on June 9, 2024

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

from chriseric1.github.io.

madkarmaa avatar madkarmaa commented on June 9, 2024

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

from chriseric1.github.io.

CE1CECL avatar CE1CECL commented on June 9, 2024

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

from chriseric1.github.io.

madkarmaa avatar madkarmaa commented on June 9, 2024

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

from chriseric1.github.io.

CE1CECL avatar CE1CECL commented on June 9, 2024

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

from chriseric1.github.io.

CE1CECL avatar CE1CECL commented on June 9, 2024

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 (

window.assets = [
) usually the assets would be defined differently (such as
};</script><script>!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}}}}();</script><script src="/assets/d170d5b12b302f315912.js" integrity=""></script><script src="/assets/35e0115547d406ec0d20.js" integrity=""></script><script src="/assets/be358c929d9afee6527f.js" integrity=""></script><script src="/assets/ac07c15f13e50948a1b2.js" integrity=""></script> </body>
"<script src="/assets/35e0115547d406ec0d20.js" integrity="">) instead

from chriseric1.github.io.

FF1Gq avatar FF1Gq commented on June 9, 2024

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

from chriseric1.github.io.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.