Skip to content

Instantly share code, notes, and snippets.

@kvba0000
Last active October 22, 2024 08:14
Show Gist options
  • Save kvba0000/bb6f6e5449db92a26101300eaa2a3100 to your computer and use it in GitHub Desktop.
Save kvba0000/bb6f6e5449db92a26101300eaa2a3100 to your computer and use it in GitHub Desktop.
This gist allows you to send fake Discord message everywhere you want! [INCL. VANILLA]

preview

🤫 Fake Discord Message

This gist allows you to send fake Discord message everywhere you want!

The snippet works both on unmodified Discord and Vencord

Important

This code by default tries to grab all functions it needs from already implemented ones by Vencord (specifically ConsoleShortcuts plugin) and if it can't find them for some reason it THEN tries to implement it by itself, so if something's broken on vanilla - use snippet with Vencord!

Usage

Usage is fairly simple. Below code returns function fakeMessage as variable but also it saves the same implementation to window.fakeMessage so you don't have to execute it multiple times. (code prevents you to do so anyways for performance reasons)

Here's an example of using this function:

// Channel ID
const CHANNEL_ID = "<id>"
// Message author ID
const AUTHOR_ID = "<id>"
// It doesn't have to be string, it can be Message object
// More on https://discord.com/developers/docs/resources/message#messages-resource
const CONTENT = "Hello"
fakeMessage(CHANNEL_ID, AUTHOR_ID, CONTENT)

...edit those variables accordingly while using this example.

Caution

Snippet has been provided by me as-is and might stop working in any moment by any reason (Discord structure change, Vencord update, plugin update etc.), I'll try to update it at my own free time. I am also not responsible for any malicious use of this.

const fakeMessage = (() => {
if(window.fakeMessage) {
console.log("You already loaded fakeMessage! Try to run it.")
return window.fakeMessage
}
const findAllByProps = window.findAllByProps || (()=>{
let _mods; webpackChunkdiscord_app.push([[Symbol()],{},r=>_mods=r.c]);
webpackChunkdiscord_app.pop();
return (...props) => {
let items = []
for (let m of Object.values(_mods)) {
try {
if (!m.exports || m.exports === window) continue;
if (props.every((x) => m.exports?.[x])) items.push(m.exports);
for (let ex in m.exports) {
if (props.every((x) => m.exports?.[ex]?.[x])) items.push(m.exports[ex]);
}
} catch {}
}
return items
}
})();
const findByProps = window.findByProps || ((...props) => findAllByProps(...props)[0]);
const find = window.find(()=>{}) === null ? window.find : ((func) => {
const items = findAllByProps()
return items.find(func)
})
const getUserProfile = window.UserProfileStore?.getUserProfile || findByProps("getUserProfile", "getGuildMemberProfile").getUserProfile
const FluxDispatcher = window.FluxDispatcher || findByProps("dispatch", "addInterceptor", "_interceptors", "_subscriptions") // Vencord one OR find
const RestAPI = window.RestAPI || find(m => typeof m === "object" && m?.del && m?.put)
const Endpoints = window.Constants?.Endpoints || findByProps("USER_PROFILE", "DM_CHANNEL", "DROPS_HEARTBEAT")
const fetchUserProfile = window.Vencord?.Util?.fetchUserProfile || (async (id) => {
const cached = getUserProfile(id)
if(cached) return cached;
FluxDispatcher.dispatch({ type: "USER_PROFILE_FETCH_START", userId: id });
const { body } = await RestAPI.get({
url: Endpoints.USER_PROFILE(id),
query: {
with_mutual_guilds: true,
with_mutual_friends_count: true
},
oldFormErrors: true
})
FluxDispatcher.dispatch({ type: "USER_UPDATE", user: body.user });
await FluxDispatcher.dispatch({ type: "USER_PROFILE_FETCH_SUCCESS", ...body });
return getUserProfile(id)
})
const { receiveMessage } = findByProps("sendMessage", "editMessage", "receiveMessage")
window.fakeMessage = async (channelId, authorId, message) => {
const id = Math.floor(Math.random() * 1000000)
const timestamp = new Date().toString()
const content = typeof message === "string" ? {content: message} : message
await fetchUserProfile(authorId)
receiveMessage(String(channelId), {
id: id,
timestamp: timestamp,
channel_id: channelId,
author: {
id: authorId
},
...content
})
}
console.log("You can use 'fakeMessage' now!")
return window.fakeMessage
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment