Skip to content

Instantly share code, notes, and snippets.

@MeguminSama
Last active March 4, 2024 00:11
Star You must be signed in to star a gist
Save MeguminSama/2cae24c9e4c335c661fa94e72235d4c4 to your computer and use it in GitHub Desktop.
Discord Experiments.js
let cache; webpackChunkdiscord_app.push([["wp_isdev_patch"], {}, r => cache=r.c]);
var UserStore = Object.values(cache).find(m => m?.exports?.default?.getUser).exports.default;
var actions = Object.values(UserStore._dispatcher._actionHandlers._dependencyGraph.nodes);
var user = UserStore.getCurrentUser();
actions.find(n => n.name === "ExperimentStore").actionHandler.CONNECTION_OPEN({
type: "CONNECTION_OPEN", user: {flags: user.flags |= 1}, experiments: [],
});
actions.find(n => n.name === "DeveloperExperimentStore").actionHandler.CONNECTION_OPEN();
webpackChunkdiscord_app.pop(); user.flags &= ~1; "done";
@UserUNP
Copy link

UserUNP commented Nov 20, 2023

Do you not know you can just ping the person instead of replying to the whole comment

@Zyrenth
Copy link

Zyrenth commented Nov 21, 2023

How? ctrl+SHIFT+I doesn't open console. so what do you do with this code?

@chrisssj2 you can use the web version, or follow this guide to enable devtools on the stable release or you could download and use any other release other than stable because discord has disabled devtools for stable a long time ago

Here you can download the PTB (64-bit) or canary (64-bit) release for Windows. Hope this helps!

@chrisssj2
Copy link

@Zyrenth I use PTB already... and it produced the results i posted... so still stuck.

@Zyrenth
Copy link

Zyrenth commented Nov 22, 2023

Have you tried following the guide I linked?

@chrisssj2
Copy link

Have you tried following the guide I linked?

Yes I did, and the settings.json already had this line in it. (PTB version) and it still doesnt work in PTB.. :(

@migue802
Copy link

doesnt work at the moment as of 2023-10-24

image

While Megumin updates the snippet, here is a working one:

c = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
u = c.find((x)=> x?.exports?.default?.getUsers).exports.default;
m = Object.values(u._dispatcher._actionHandlers._dependencyGraph.nodes);

u.getCurrentUser().flags |= 1;
m.find((x)=>x.name === "DeveloperExperimentStore").actionHandler["CONNECTION_OPEN"]();
try {m.find((x)=>x.name === "ExperimentStore").actionHandler["OVERLAY_INITIALIZE"]({user:{flags: 1}})} catch {}
m.find((x)=>x.name === "ExperimentStore").storeDidChange()

If someone wants to automate this snippet with BetterDiscord, just create a plugin file on the plugins folder called Experiments.plugin.js with this code:

/**
 * @name Experiments
 * @author migue802
 * @description Experiments 👍
 * @version 1.0.0
 */

module.exports = class Experiments {
    load() {}

    start = () => {
        var c = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
        var u = c.find((x)=> x?.exports?.default?.getUsers).exports.default;
        var m = Object.values(u._dispatcher._actionHandlers._dependencyGraph.nodes);

        u.getCurrentUser().flags |= 1;
        m.find((x)=>x.name === "DeveloperExperimentStore").actionHandler["CONNECTION_OPEN"]();
        try {m.find((x)=>x.name === "ExperimentStore").actionHandler["OVERLAY_INITIALIZE"]({user:{flags: 1}})} catch {}
        m.find((x)=>x.name === "ExperimentStore").storeDidChange()
    }

    stop = () => {}
}

(Note that what I've modified from @Zyrenth's code is just the variables, for some reason it doesn't work if you don't declare them with var or const)

@chrisssj2
Copy link

THanks this works!! been looking for this for months now again!

@fajfaj1
Copy link

fajfaj1 commented Nov 25, 2023

Fails for me (web and stable build with console enabled).
UserStore._dispatcher seems to return undefined.
I have also tried with the renamed vars.

@Zyrenth
Copy link

Zyrenth commented Nov 26, 2023

Fails for me (web and stable build with console enabled). UserStore._dispatcher seems to return undefined. I have also tried with the renamed vars.

@fajfaj1 Discord has changed its bundler and this broke a lot of snippets, I have already sent a working version above, hope it helps!

@TheByKotik
Copy link

If someone wants to automate this snippet with BetterDiscord, just create a plugin file on the plugins folder called Experiments.plugin.js with this code:

/**
 * @name Experiments
 * @author migue802
 * @description Experiments 👍
 * @version 1.0.0
 */

module.exports = class Experiments {
    load() {}

    start = () => {
        var c = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
        var u = c.find((x)=> x?.exports?.default?.getUsers).exports.default;
        var m = Object.values(u._dispatcher._actionHandlers._dependencyGraph.nodes);

        u.getCurrentUser().flags |= 1;
        m.find((x)=>x.name === "DeveloperExperimentStore").actionHandler["CONNECTION_OPEN"]();
        try {m.find((x)=>x.name === "ExperimentStore").actionHandler["OVERLAY_INITIALIZE"]({user:{flags: 1}})} catch {}
        m.find((x)=>x.name === "ExperimentStore").storeDidChange()
    }

    stop = () => {}
}

(Note that what I've modified from @Zyrenth's code is just the variables, for some reason it doesn't work if you don't declare them with var or const)

Could you please publish this plugin to BetterDiscord and create a repository?

@migue802
Copy link

migue802 commented Nov 29, 2023

Could you please publish this plugin to BetterDiscord and create a repository?

@TheByKotik this isn't my code, I've just pasted @MeguminSama's code into there + I don't want to deal with a lot of people asking me how to install it on a support Discord server + I don't want to maintain the code + I don't know what it even does lol

So I won't do anything with that code besides using it on my client, so if someone else wants to publish it with @MeguminSama's permission then go ahead, I don't want to deal with BetterDiscord plugins at the moment

@MeguminSama
Copy link
Author

Gist has been updated. My bad for taking so long. It was a tiny change.

@seailz
Copy link

seailz commented Dec 1, 2023

looks like this one is broken again

@SJ-Tom
Copy link

SJ-Tom commented Dec 1, 2023

looks like this one is broken again

I have the same issue since today. It looks like some plugin libraries are breaking it. Error message is

Uncaught TypeError: Cannot convert undefined or null to object
    at Function.values (<anonymous>)
    at <anonymous>:1:73
    at e (sentry.0ddcf0c0bd2f89c81d7f.js:1:7629)
    at s.handlePush (renderer.js:5:52230)
    at WebpackModules.handlePush (0PluginLibrary.plugin.js:3189:24)
    at <anonymous>:1:25

@RaspberryKitty1
Copy link

If someone wants to automate this snippet with BetterDiscord, just create a plugin file on the plugins folder called Experiments.plugin.js with this code:

/**
 * @name Experiments
 * @author migue802
 * @description Experiments 👍
 * @version 1.0.0
 */

module.exports = class Experiments {
    load() {}

    start = () => {
        var c = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
        var u = c.find((x)=> x?.exports?.default?.getUsers).exports.default;
        var m = Object.values(u._dispatcher._actionHandlers._dependencyGraph.nodes);

        u.getCurrentUser().flags |= 1;
        m.find((x)=>x.name === "DeveloperExperimentStore").actionHandler["CONNECTION_OPEN"]();
        try {m.find((x)=>x.name === "ExperimentStore").actionHandler["OVERLAY_INITIALIZE"]({user:{flags: 1}})} catch {}
        m.find((x)=>x.name === "ExperimentStore").storeDidChange()
    }

    stop = () => {}
}

(Note that what I've modified from @Zyrenth's code is just the variables, for some reason it doesn't work if you don't declare them with var or const)

Could you please publish this plugin to BetterDiscord and create a repository?

image
broken

@RaspberryKitty1
Copy link

c = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
u = c.find((x)=> x?.exports?.default?.getUsers).exports.default;
m = Object.values(u._dispatcher._actionHandlers._dependencyGraph.nodes);

u.getCurrentUser().flags |= 1;
m.find((x)=>x.name === "DeveloperExperimentStore").actionHandler["CONNECTION_OPEN"]();
try {m.find((x)=>x.name === "ExperimentStore").actionHandler["OVERLAY_INITIALIZE"]({user:{flags: 1}})} catch {}
m.find((x)=>x.name === "ExperimentStore").storeDidChange()

works as of 30.10.2023, PTB

image

@foursplaysroblox
Copy link

plugin is not working anymore

@Zyrenth
Copy link

Zyrenth commented Dec 2, 2023

Patched version:

let cache; webpackChunkdiscord_app.push([["wp_isdev_patch"], {}, r => cache=r.c]);
var UserStore = Object.values(cache).find(m => m?.exports?.default?.getUsers).exports.default;
var actions = Object.values(UserStore._dispatcher._actionHandlers._dependencyGraph.nodes);
var user = UserStore.getCurrentUser();
actions.find(n => n.name === "ExperimentStore").actionHandler.CONNECTION_OPEN({
	type: "CONNECTION_OPEN", user: {flags: user.flags |= 1}, experiments: [],
});
actions.find(n => n.name === "DeveloperExperimentStore").actionHandler.CONNECTION_OPEN();
webpackChunkdiscord_app.pop(); user.flags &= ~1; "done";

@NullClock
Copy link

NullClock commented Dec 3, 2023

@Zyrenth

Patched version:

let cache; webpackChunkdiscord_app.push([["wp_isdev_patch"], {}, r => cache=r.c]);
var UserStore = Object.values(cache).find(m => m?.exports?.default?.getUsers).exports.default;
var actions = Object.values(UserStore._dispatcher._actionHandlers._dependencyGraph.nodes);
var user = UserStore.getCurrentUser();
actions.find(n => n.name === "ExperimentStore").actionHandler.CONNECTION_OPEN({
	type: "CONNECTION_OPEN", user: {flags: user.flags |= 1}, experiments: [],
});
actions.find(n => n.name === "DeveloperExperimentStore").actionHandler.CONNECTION_OPEN();
webpackChunkdiscord_app.pop(); user.flags &= ~1; "done";

Thanks

@RaspberryKitty1
Copy link

Patched version:

let cache; webpackChunkdiscord_app.push([["wp_isdev_patch"], {}, r => cache=r.c]);
var UserStore = Object.values(cache).find(m => m?.exports?.default?.getUsers).exports.default;
var actions = Object.values(UserStore._dispatcher._actionHandlers._dependencyGraph.nodes);
var user = UserStore.getCurrentUser();
actions.find(n => n.name === "ExperimentStore").actionHandler.CONNECTION_OPEN({
	type: "CONNECTION_OPEN", user: {flags: user.flags |= 1}, experiments: [],
});
actions.find(n => n.name === "DeveloperExperimentStore").actionHandler.CONNECTION_OPEN();
webpackChunkdiscord_app.pop(); user.flags &= ~1; "done";

works thanks

@KingGamingYT
Copy link

This worked once and now it's throwing the same "cannot convert undefined or null to object" as before, odd
It says it happens at this line, but I doubt that to be the root cause
image

@Zyrenth
Copy link

Zyrenth commented Dec 5, 2023

This worked once and now it's throwing the same "cannot convert undefined or null to object" as before

@KingGamingYT Yes, and I've patched it already, scroll up a bit and you'll see.

@KingGamingYT
Copy link

KingGamingYT commented Dec 5, 2023

This worked once and now it's throwing the same "cannot convert undefined or null to object" as before

@KingGamingYT Yes, and I've patched it already, scroll up a bit and you'll see.

I am using your patched version. I've observed that if I start discord, and then run the code, it will work, but upon opening the status menu, the options in settings go away, and any attempt to run the code again will result in the aforementioned error until discord is restarted.
image

@Zyrenth
Copy link

Zyrenth commented Dec 5, 2023

@KingGamingYT I can't reproduce your issue, the options don't disappear and it works fine but the snippet isn't meant to be run twice.

@JerZSlayR
Copy link

JerZSlayR commented Dec 7, 2023

So I got the experimental tab, when trying to enable any settings I'm getting a message saying "Warning: Server did not send experiment config. You may need to enable "Send to Client" box in admin UI", no idea where this is. Just wanna stream hdr content without it flashbanging anyone who clicks on lol.

@Zyrenth
Copy link

Zyrenth commented Dec 7, 2023

So I got the experimental tab, when trying to enable any settings I'm getting a message saying "You may need to enable "Send to Client" box in admin UI", no idea where this is. Just wanna stream hdr content without it flashbanging anyone who clicks on lol.

@JerZSlayR you can ignore that, it doesn't affect the experiments

@JerZSlayR
Copy link

So I got the experimental tab, when trying to enable any settings I'm getting a message saying "You may need to enable "Send to Client" box in admin UI", no idea where this is. Just wanna stream hdr content without it flashbanging anyone who clicks on lol.

@JerZSlayR you can ignore that, it doesn't affect the experiments

So does the HDR streaming experimental mode not work then? Was testing last night and I couldn’t get it to work at all, streams still too bright with hdr enabled, thought it has something to do with that setting.

@Zyrenth
Copy link

Zyrenth commented Dec 8, 2023

So does the HDR streaming experimental mode not work then? Was testing last night and I couldn’t get it to work at all, streams still too bright with hdr enabled, thought it has something to do with that setting.

@JerZSlayR Just because you've enabled it client side might not mean that it will work, most of these experiments are locked server side as well and it's in the FAQ:

Q: "I enabled an experiment but can't use it!!!!"
A: Discord locks many experiments on the API. Enabling it on the client does not bypass this.

@Zyrenth
Copy link

Zyrenth commented Feb 29, 2024

Another patch because we love discord:
(as of writing this the update is only pushed to canary and ptb)

let cache; webpackChunkdiscord_app.push([["wp_isdev_patch"], {}, r => cache=r.c]);
var UserStore = Object.values(cache).find(m => m?.exports?.default?.getUser).exports.default;
var actions = Object.values(UserStore._dispatcher._actionHandlers._dependencyGraph.nodes);
var user = UserStore.getCurrentUser();
actions.find(n => n.name === "ExperimentStore").actionHandler.CONNECTION_OPEN({
	type: "CONNECTION_OPEN", user: {flags: user.flags |= 1}, experiments: [],
});
actions.find(n => n.name === "DeveloperExperimentStore").actionHandler.CONNECTION_OPEN();
webpackChunkdiscord_app.pop(); user.flags &= ~1; "done";

@MeguminSama
Copy link
Author

@Zyrenth thanks for the patch. Gist has been updated.

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