Skip to content

Instantly share code, notes, and snippets.

@NullDev
Last active April 19, 2024 14:47
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save NullDev/cac59e13967aecf0360cf35f88ce8932 to your computer and use it in GitHub Desktop.
Save NullDev/cac59e13967aecf0360cf35f88ce8932 to your computer and use it in GitHub Desktop.
Some Discord console tricks

Discord Console Tricks (Experiments, Dev Stuff, etc)

INSTRUCTIONS FOR ALL OF THEM:

  • Open DevTools in Discord with CTRL + SHIFT + i (ONLY POSSIBLE IN CANARY AND PBT ANYMORE)
  • Paste Snippet
  • Edit it. (optional: if instructed)
  • Hit Enter.

Enable Experiments and Dev-Only Options:

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";

Use REST API with your token & cookies

const api = webpackChunkdiscord_app.push([[Symbol()], {}, ({c}) => Object.values(c)])
    .find((x) => x?.exports?.Z?.getAPIBaseURL).exports.Z; webpackChunkdiscord_app.pop();

Example usage:

await api.get({ url: "/guilds/<ID>?with_counts=true" });
await api.get({ url: "/guilds/<ID>/channels" });
// or
await api.post({url: "/users/@me/referrals/<ID>/preview"});

Send Audio file as Voice Message

(() => {
const uploaded_filename = "<UPLOAD_FILENAME_HERE>";
const channel_id = "<CHANNEL_ID_HERE>";
const c = webpackChunkdiscord_app.push([[Symbol()], {}, ({c}) => Object.values(c)]);
const a = c.find((x) => x?.exports?.Z?.getAPIBaseURL).exports.Z;
webpackChunkdiscord_app.pop(); 
a.post({url: "/channels/" + channel_id + "/messages", body: {"flags": 1 << 13, "attachments": [{"id": "0", "filename": "file.ogg", "uploaded_filename": uploaded_filename, "waveform": "=", "duration_secs": 1}]}
})})()

Usage:

  • open dev tools, go to network tab
  • send an audio file in any channel, watch for request to "/channels//attachments"
  • click on the request, go to the response tab and copy the value of the "upload_filename" property
  • replace <UPLOAD_FILENAME_HERE> with value above
  • replace <CHANNEL_ID_HERE> with the channel id you want to send the message in

Generate friend link

await (webpackChunkdiscord_app.push([[''],{},e=>m=Object.values(e.c)]),m)
.find(m => m.exports?.Z?.createFriendInvite).exports.Z.createFriendInvite()

Use the code from the output and put https://discord.gg/ in front of it. e.g.: https://discord.gg/abcxyz
Note: If you generate a new link, the old one will be invalidated! Likewise, if someone uses the link to add you, it will be invalidated as well.

Change HypeSquad House

house = 1;
(webpackChunkdiscord_app.push([[""],{},e=>{m=[];for(let r in e.c)m.push(e.c[r])}]),m)
.find((e=>e?.exports?.Z?.joinHypeSquadOnline)).exports.Z.joinHypeSquadOnline({houseID: "HOUSE_" + house})

Change the house variable:

  • 1 = Bravery
  • 2 = Brilliance
  • 3 = Balance

List channels that include "bad names" so Discovery and Partner Program isn't blocked

NOTE: This snippet requires _mods and findByProps from "general functions" to be set.

let {getChannel} = findByProps("getMutableGuildChannelsForGuild");
(async (guildId) => {
    let {nsfw_properties} = await findByProps("getAPIBaseURL").get(`/guilds/${guildId}/discovery-requirements`)
        .then(({text}) => JSON.parse(text));
    for (let c of nsfw_properties.channels) {
        console.log(getChannel(c).name, nsfw_properties.channels_banned_keywords[c]);
    }
})("<ID>")

Some general functions to develop new tricks

Define _mods

Defines the _mods constant so different findBy/get functions dont cause errors trying defining the same constant. NECESSARY FOR ALL FINDBY/GET FUNCTIONS UNLESS STATED OTHERWISE.

const _mods = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
webpackChunkdiscord_app.pop();

findByProps

Gets a module by one (or more) of its properties.

const findByProps = (...props) => {
    for (let m of _mods) {
        try {
            if (!m.exports || m.exports === window) continue;
            if (props.every((x) => m.exports?.[x])) return m.exports;

            for (let ex in m.exports) {
                if (props.every((x) => m.exports?.[ex]?.[x])) return m.exports[ex];
            }
        } catch {}
    }
}

getStore

Gets a store by its name.

const getStore = (store) => {
    return Object.values(
        Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes
    ).filter(s => s.name === store)[0];
};

getActionHandler

Gets an ActionHandler by its store and name.

const getActionHandler = (store, actionHandler) => {
    let stores = Object.values(Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes).filter(s => s.name === store);
    let found;

    for (var store of stores) {
        if (!found && store.actionHandler[actionHandler]) found = store;
    };

    if (found) return found.actionHandler[actionHandler];
    else return console.error(`${actionHandler} action handler could not found!`);
};

getAllFunctions

Gets all functions of all modules.

const getAllFunctions = () => {
    return _mods.filter(m => typeof m?.exports?.Z === "object").map(m => Object.entries(m?.exports?.Z)
        .filter(entry => typeof entry[1] === "function").map(entry => entry[0]));
};

searchFunctions

Gets a Function by a name query.

const searchFunctions = (search) => {
    return _mods.filter(m => typeof m?.exports?.Z === "object")
        .map(m => Object.entries(m?.exports?.Z).filter(entry => typeof entry[1] === "function" && entry[0].toLowerCase().includes(search))
        .map(entry => entry[0])).filter(array => array.length !== 0);
};

searchStores

Gets a store by a name query.

const searchStores = (query) => {
    return Object.fromEntries(_mods.find(x => x?.exports?.Z?.connectStores).Store.getAll()
        .filter(store => store.getName().toLowerCase().includes(query)).map(matchingStore => [matchingStore.getName(), matchingStore]));
};

searchActionHandlers

Gets an action handler by a name query.

const searchActionHandlers = (query) => {
    return Object.keys(Object.values(_mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[0])
        .filter(key => key.toLowerCase().includes(query));
};

findModule

equivelent to _mods.find(). Just a shortcut for lazy people

const findModule = (func) => _mods.find(func)

Discord Modules

May or may not be valid.
From: https://rauenzi.github.io/BDPluginLibrary/docs/modules_discordmodules.js.html

React - findByProps("createElement", "cloneElement")
ReactDOM - findByProps("render", "findDOMNode")

GuildStore - findByProps("getGuild")
SortedGuildStore - findByProps("getSortedGuilds")
SelectedGuildStore - findByProps("getLastSelectedGuildId")
GuildSync - findByProps("getSyncedGuilds")
GuildInfo - findByProps("getAcronym")
GuildChannelsStore - findByProps("getChannels", "getDefaultChannel")
GuildMemberStore - findByProps("getMember")
MemberCountStore - findByProps("getMemberCounts")
GuildEmojiStore - findByProps("getEmojis")
GuildActions - findByProps("requestMembers")
GuildPermissions - findByProps("getGuildPermissions")

/* Channel Store & Actions */
ChannelStore - findByProps("getChannel", "getDMFromUserId")
SelectedChannelStore - findByProps("getLastSelectedChannelId")
ChannelActions - findByProps("selectChannel")
PrivateChannelActions - findByProps("openPrivateChannel")

/* Current User Info, State and Settings */
UserInfoStore - findByProps("getSessionId")
UserSettingsStore - findByProps("guildPositions")
StreamerModeStore - findByProps("hidePersonalInformation")
UserSettingsUpdater - findByProps("updateRemoteSettings")
OnlineWatcher - findByProps("isOnline")
CurrentUserIdle - findByProps("isIdle")
RelationshipStore - findByProps("isBlocked", "getFriendIDs")
RelationshipManager - findByProps("addRelationship")
MentionStore - findByProps("getMentions")

/* User Stores and Utils */
UserStore - findByProps("getCurrentUser", "getUser")
UserStatusStore - findByProps("getStatus", "getState")
UserTypingStore - findByProps("isTyping")
UserActivityStore - findByProps("getActivity")
UserNameResolver - findByProps("getName")
UserNoteStore - findByProps("getNote")
UserNoteActions - findByProps("updateNote")

/* Emoji Store and Utils */
EmojiInfo - findByProps("isEmojiDisabled")
EmojiUtils - findByProps("getGuildEmoji")
EmojiStore - findByProps("getByCategory", "EMOJI_NAME_RE")

/* Invite Store and Utils */
InviteStore - findByProps("getInvites")
InviteResolver - findByProps("resolveInvite")
InviteActions - findByProps("acceptInvite")

/* Discord Objects & Utils */
DiscordConstants - findByProps("Permissions", "ActivityTypes", "StatusTypes")
DiscordPermissions - findByProps("Permissions", "ActivityTypes", "StatusTypes").Permissions
Permissions - findByProps("computePermissions")
ColorConverter - findByProps("hex2int")
ColorShader - findByProps("darken")
ClassResolver - findByProps("getClass")
ButtonData - findByProps("ButtonSizes")
NavigationUtils - findByProps("transitionTo", "replaceWith", "getHistory")
KeybindStore - findByProps("keyToCode")

/* Discord Messages */
MessageStore - findByProps("getMessage", "getMessages")
ReactionsStore - findByProps("getReactions", "_dispatcher")
MessageActions - findByProps("jumpToMessage", "_sendMessage")
MessageQueue - findByProps("enqueue")

/* Experiments */
ExperimentStore - findByProps("getExperimentOverrides")
ExperimentsManager - findByProps("isDeveloper")
CurrentExperiment - findByProps("getExperimentId")

Snippet API:

This is a snippet to get all of the functions and modules in one object.
Access them using snippetApi.

=> 3-discord-cli-snippet-api.js

class SnippetApi {
constructor() {
const _mods = webpackChunkdiscord_app.push([[Symbol()],{},({c})=>Object.values(c)]);
this._mods = _mods;
webpackChunkdiscord_app.pop();
}
findByProps = (...props) => {
for (let m of this._mods) {
try {
if (!m.exports || m.exports === window) continue;
if (props.every((x) => m.exports?.[x])) return m.exports;
for (let ex in m.exports) {
if (props.every((x) => m.exports?.[ex]?.[x])) return m.exports[ex];
}
} catch {}
}
}
getStore = (store) => {
return Object.values(Object.values(this._mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes).filter(s => s.name === store)[0];
};
getActionHandler = (store, actionHandler) => {
let stores = Object.values(Object.values(this._mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[3].nodes).filter(s => s.name === store);
let found;
for (var store of stores) {
if (!found && store.actionHandler[actionHandler]) found = store;
};
if (found) return found.actionHandler[actionHandler];
else return console.error(`${actionHandler} action handler could not found!`);
};
getAllFunctions = () => {
return this._mods.filter(m => typeof m?.exports?.Z === "object").map(m => Object.entries(m?.exports?.Z).filter(entry => typeof entry[1] === "function").map(entry => entry[0]));
};
searchFunctions = (query) => {
return this._mods.filter(m => typeof m?.exports?.Z === "object").map(m => Object.entries(m?.exports?.Z).filter(entry => typeof entry[1] === "function" && entry[0].toLowerCase().includes(search)).map(entry => entry[0])).filter(array => array.length !== 0);
};
searchStores = (query) => {
return Object.fromEntries(this._mods.find(x => x?.exports?.Z?.connectStores).Store.getAll().filter(store => store.getName().toLowerCase().includes(query)).map(matchingStore => [matchingStore.getName(), matchingStore]));
};
searchActionHandlers = (query) => {
return Object.keys(Object.values(this._mods.find(x => x?.exports?.default?.getUsers).exports.default._dispatcher._actionHandlers)[0]).filter(key => key.toLowerCase().includes(query));
};
findModule = (func) => this.this._mods.find(func)
get React() {return this.findByProps("createElement", "cloneElement");}
get ReactDOM() {return this.findByProps("render", "findDOMNode");}
/* Guild Info, Stores, and Utilities */
get GuildStore() {return this.findByProps("getGuild");}
get SortedGuildStore() {return this.findByProps("getSortedGuilds");}
get SelectedGuildStore() {return this.findByProps("getLastSelectedGuildId");}
get GuildSync() {return this.findByProps("getSyncedGuilds");}
get GuildInfo() {return this.findByProps("getAcronym");}
get GuildChannelsStore() {return this.findByProps("getChannels", "getDefaultChannel");}
get GuildMemberStore() {return this.findByProps("getMember");}
get MemberCountStore() {return this.findByProps("getMemberCounts");}
get GuildEmojiStore() {return this.findByProps("getEmojis");}
get GuildActions() {return this.findByProps("requestMembers");}
get GuildPermissions() {return this.findByProps("getGuildPermissions");}
/* Channel Store & Actions */
get ChannelStore() {return this.findByProps("getChannel", "getDMFromUserId");}
get SelectedChannelStore() {return this.findByProps("getLastSelectedChannelId");}
get ChannelActions() {return this.findByProps("selectChannel");}
get PrivateChannelActions() {return this.findByProps("openPrivateChannel");}
/* Current User Info, State and Settings */
get UserInfoStore() {return this.findByProps("getSessionId");}
get UserSettingsStore() {return this.findByProps("guildPositions");}
get StreamerModeStore() {return this.findByProps("hidePersonalInformation");}
get UserSettingsUpdater() {return this.findByProps("updateRemoteSettings");}
get OnlineWatcher() {return this.findByProps("isOnline");}
get CurrentUserIdle() {return this.findByProps("isIdle");}
get RelationshipStore() {return this.findByProps("isBlocked", "getFriendIDs");}
get RelationshipManager() {return this.findByProps("addRelationship");}
get MentionStore() {return this.findByProps("getMentions");}
/* User Stores and Utils */
get UserStore() {return this.findByProps("getCurrentUser", "getUser");}
get UserStatusStore() {return this.findByProps("getStatus", "getState");}
get UserTypingStore() {return this.findByProps("isTyping");}
get UserActivityStore() {return this.findByProps("getActivity");}
get UserNameResolver() {return this.findByProps("getName");}
get UserNoteStore() {return this.findByProps("getNote");}
get UserNoteActions() {return this.findByProps("updateNote");}
/* Emoji Store and Utils */
get EmojiInfo() {return this.findByProps("isEmojiDisabled");}
get EmojiUtils() {return this.findByProps("getGuildEmoji");}
get EmojiStore() {return this.findByProps("getByCategory", "EMOJI_NAME_RE");}
/* Invite Store and Utils */
get InviteStore() {return this.findByProps("getInvites");}
get InviteResolver() {return this.findByProps("resolveInvite");}
get InviteActions() {return this.findByProps("acceptInvite");}
/* Discord Objects & Utils */
get DiscordConstants() {return this.findByProps("Permissions", "ActivityTypes", "StatusTypes");}
get DiscordPermissions() {return this.findByProps("Permissions", "ActivityTypes", "StatusTypes").Permissions;}
get Permissions() {return this.findByProps("computePermissions");}
get ColorConverter() {return this.findByProps("hex2int");}
get ColorShader() {return this.findByProps("darken");}
get TinyColor() {return WebpackModules.getByPrototypes("toRgb");}
get ClassResolver() {return this.findByProps("getClass");}
get ButtonData() {return this.findByProps("ButtonSizes");}
get NavigationUtils() {return this.findByProps("transitionTo", "replaceWith", "getHistory");}
get KeybindStore() {return this.findByProps("keyToCode");}
/* Discord Messages */
get MessageStore() {return this.findByProps("getMessage", "getMessages");}
get ReactionsStore() {return this.findByProps("getReactions", "_dispatcher");}
get MessageActions() {return this.findByProps("jumpToMessage", "_sendMessage");}
get MessageQueue() {return this.findByProps("enqueue");}
/* Experiments */
get ExperimentStore() {return this.findByProps("getExperimentOverrides");}
get ExperimentsManager() {return this.findByProps("isDeveloper");}
get CurrentExperiment() {return this.findByProps("getExperimentId");}
/* Streams */
get StreamStore() {return this.findByProps("getAllActiveStreams", "getStreamForUser");}
get StreamPreviewStore() {return this.findByProps("getIsPreviewLoading", "getPreviewURL");}
/* Images, Avatars and Utils */
get ImageResolver() {return this.findByProps("getUserAvatarURL", "getGuildIconURL");}
get ImageUtils() {return this.findByProps("getSizedImageSrc");}
get AvatarDefaults() {return this.findByProps("getUserAvatarURL", "DEFAULT_AVATARS");}
/* Drag & Drop */
get DNDSources() {return this.findByProps("addTarget");}
get DNDObjects() {return this.findByProps("DragSource");}
/* Electron & Other Internals with Utils*/
get ElectronModule() {return this.findByProps("setBadge");}
get Flux() {return this.findByProps("Store", "connectStores");}
get Dispatcher() {return this.findByProps("dirtyDispatch");}
get PathUtils() {return this.findByProps("hasBasename");}
get NotificationModule() {return this.findByProps("showNotification");}
get RouterModule() {return this.findByProps("Router");}
get APIModule() {return this.findByProps("getAPIBaseURL");}
get AnalyticEvents() {return this.findByProps("AnalyticEventConfigs");}
get Buffers() {return this.findByProps("Buffer", "kMaxLength");}
get DeviceStore() {return this.findByProps("getDevices");}
get SoftwareInfo() {return this.findByProps("os");}
get i18n() {return this.findByProps("Messages", "languages");}
/* Media Stuff (Audio/Video) */
get MediaDeviceInfo() {return this.findByProps("Codecs", "MediaEngineContextTypes");}
get MediaInfo() {return this.findByProps("getOutputVolume");}
get MediaEngineInfo() {return this.findByProps("determineMediaEngine");}
get VoiceInfo() {return this.findByProps("getEchoCancellation");}
get SoundModule() {return this.findByProps("playSound");}
/* Window, DOM, HTML */
get WindowInfo() {return this.findByProps("isFocused", "windowSize");}
get DOMInfo() {return this.findByProps("canUseDOM");}
/* Locale/Location and Time */
get Moment() {return this.findByProps("parseZone");}
get LocationManager() {return this.findByProps("createLocation");}
get Timestamps() {return this.findByProps("fromTimestamp");}
/* Strings and Utils */
get StringFormats() {return this.findByProps("a", "z");}
get StringUtils() {return this.findByProps("toASCII");}
/* URLs and Utils */
get URLParser() {return this.findByProps("Url", "parse");}
get ExtraURLs() {return this.findByProps("getArticleURL");}
/* Text Processing */
get hljs() {return this.findByProps("highlight", "highlightBlock");}
get SimpleMarkdown() {return this.findByProps("parseBlock", "parseInline", "defaultOutput");}
/* DOM/React Components */
/* ==================== */
get LayerManager() {return this.findByProps("popLayer", "pushLayer");}
get UserSettingsWindow() {return this.findByProps("open", "updateAccount");}
get ChannelSettingsWindow() {return this.findByProps("open", "updateChannel");}
get GuildSettingsWindow() {return this.findByProps("open", "updateGuild");}
/* Modals */
get ModalActions() {return this.findByProps("openModal", "updateModal");}
get ModalStack() {return this.findByProps("push", "update", "pop", "popWithKey");}
get UserProfileModals() {return this.findByProps("fetchMutualFriends", "setSection");}
get ChangeNicknameModal() {return this.findByProps("open", "changeNickname");}
get CreateChannelModal() {return this.findByProps("open", "createChannel");}
get PruneMembersModal() {return this.findByProps("open", "prune");}
get NotificationSettingsModal() {return this.findByProps("open", "updateNotificationSettings");}
/* Popouts */
get PopoutStack() {return this.findByProps("open", "close", "closeAll");}
get PopoutOpener() {return this.findByProps("openPopout");}
/* Context Menus */
get ContextMenuActions() {return this.findByProps("openContextMenu");}
/* Misc */
get FlexChild() {return this.findByProps("Child");}
get Titles() {return this.findByProps("Tags", "default");}
get Tooltip() {return this.findByProps("TooltipContainer").TooltipContainer;}
/* Scrollers */
get ScrollerThin() {return this.findByProps("ScrollerThin").ScrollerThin;}
get ScrollerAuto() {return this.findByProps("ScrollerAuto").ScrollerAuto;}
get AdvancedScrollerThin() {return this.findByProps("AdvancedScrollerThin").AdvancedScrollerThin;}
get AdvancedScrollerAuto() {return this.findByProps("AdvancedScrollerAuto").AdvancedScrollerAuto;}
get AdvancedScrollerNone() {return this.findByProps("AdvancedScrollerNone").AdvancedScrollerNone;}
get Dropdown() {return this.findByProps("SingleSelect").SingleSelect;}
};
window.snippetApi = new SnippetApi();
@R2kip
Copy link

R2kip commented Feb 28, 2024

VM1043:3 Uncaught TypeError: Cannot convert undefined or null to object
at Function.values ()
at :3:81
at t (sentry.0806da5664eb9fbf3615.js:1:6757)
at new SnippetApi (:3:47)
at :225:21

ptb 269561 (2b2b368) Host 1.0.1057 x64 (44185) Windows 10 64-bit (10.0.19045)

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