Skip to content

Instantly share code, notes, and snippets.

@elendil7
Forked from junebug12851/readme.md
Last active April 13, 2024 18:23
Show Gist options
  • Save elendil7/6cd099fc8516e608bb1a9f4df7cd86c8 to your computer and use it in GitHub Desktop.
Save elendil7/6cd099fc8516e608bb1a9f4df7cd86c8 to your computer and use it in GitHub Desktop.
Extract all Discord emojis and stickers from all servers

Important Note!

Doing this requires running a script inside Discord, historically Discord has allowed these perfectly fine but it was for advanced people only and Discod discovered non-advanced users were copying and pasting random scripts people gave them which ended up being malicious and harmful to their account.

Discord has since blocked access to scripts unless you enable a hidden setting. The script below is open source and commented. Anyone is welcome to verify the legitimacy of it. It's very simple in how it works. However if you proceed further and enable custom scripts, I highly reccomend to disable it afterwards unless you know what you are doing. There's a reason Discord disabled this feature, don't even run scripts without knowing what they do first.

By proceeding you understand this warning and risks

Copyright Noice

This is intended for personal use only, as in, to download to your computer and not redistribute or give or use anywhere or to anyone. Obiosuly stickers and emojis are privtae to servers.

Actually this method was invented to get my enojis and stickers off of my own servers because of a hardware failure and I lost the original files. This method though will pull from every server your in so just respect peoples privacy and copyrights and dont let them leave your computer unless you own rights to them.

What this will do

Download all non-animated stickers and all emojis animated or not in their original form to your computer. webp files will be converted to png for easy universal access.

Step 1: Add this to the Discord settings file (And restart Discord by completely quitting and re-opening)

%appdata%/discord/settings.json

"DANGEROUS_ENABLE_DEVTOOLS_ONLY_ENABLE_IF_YOU_KNOW_WHAT_YOURE_DOING": true

Step 2: Do this inside of Discord

Ctrl + Shift + I

Step 3: Enter this in the console and press enter

// Holds All URLs
var urls = '';

// Internal function to add a url to the list of urls
function addAssetUrl(url) {
	// If It's a .webp file, trim off the end and make it a png
	if (url.split('.webp').length > 1) {
		url = url.split('.webp')[0];
		url += '.png';
	}

	// If it's a .gif, .apng, or .png file, trim off the end and keep the extension as it is
	else if (url.split('.gif').length > 1) {
		url = url.split('.gif')[0];
		url += '.gif';
	} else if (url.split('.apng').length > 1) {
		url = url.split('.apng')[0];
		url += '.apng';
	} else if (url.split('.png').length > 1) {
		url = url.split('.png')[0];
		url += '.png';
	}

	// Add url to list of urls
	urls += url + '\n';
}

// Function you execute to capture currently loaded emojis
function getEmojis() {
	// Grab all * potential * emoji links, some may be false
	var p = document.querySelectorAll('[class*=emojiItem]');

	// Loop through them
	for (var i = 0; i < p.length; i++) {
		// Get the image link contained inside the emoji
		// and make sure there actually is an image link
		// Remember, some that are captured arent actually emojis so we skip over them
		var url = p[i].children[0].src;
		if (!url) continue;

		// We've conformed it's an enoji link, add it to the list of urls
		addAssetUrl(url);
	}

	// This is just for fun, itsn ot nesesary, it tell you how many emoji links it captured
	// this time around
	return p.length;
}

// Same things but for stickers
function getStickers() {
	// Same thing but gets sticker links
	var p = document.querySelectorAll('[class*=stickerAsset]');

	// Loop through all stickers
	for (var i = 0; i < p.length; i++) {
		// Get sticker URL and make sure it's a valid sticker
		var url = p[i].src;
		if (!url) continue;

		// We've verified it's an actual sticker URL, add to list of links
		addAssetUrl(url);
	}

	// Again, for fun, not needed, just tells you how many stickers it captured
	return p.length;
}

// List all links, many will be duplicate which is fine
function listLinks() {
	console.log(urls);
}

// For every URL, download it to default download location (browser settings)
function downloadAll() {
	// Split the urls into an array
	var urls = urls.split('\n');

	// Loop through all urls
	for (var i = 0; i < urls.length; i++) {
		// Create an anchor element
		var a = document.createElement('a');

		// Set the href to the current url
		a.href = urls[i];

		// Click the anchor element to download the file
		a.click();
	}
}

// Get element of specific class
function getClassDespiteObfuscatedClassName(knownClassName) {
	// convert to lowercase
	knownClassName = knownClassName.toLowerCase();

	// Get all elements in the DOM
	const allElements = document.getElementsByTagName('*');

	// store elems
	let elems = [];

	// Loop through all elements
	for (let i = 0; i < allElements.length; ++i) {
		const element = allElements[i];

		// Get the list of classes for the current element
		const classes = element.classList;

		// Loop through each class in the class list
		for (let j = 0; j < classes.length; ++j) {
			// grab the class name
			const className = classes[j];

			console.log('Checking class: ' + className);

			// Check if the lowercase class name contains the known class name
			if (className.toLowerCase().includes(knownClassName)) {
				// add to elems
				elems.push(element);
				// break out of loop
				break;
			}
		}
	}

	if (elems.length < 1) {
		throw new Error('No elements found with class: ' + knownClassName);
	}

	// return list of elements
	return elems;
}

// Wait function
function wait(seconds) {
	return new Promise((resolve) => {
		setTimeout(resolve, seconds * 1000);
	});
}

// Timeout function
async function waitForSeconds(seconds) {
	console.log('Start');
	await wait(seconds);
	console.log(`Waited for ${seconds} seconds`);
}

// Main code flow (async, self invoking function)
(async () => {
	console.log('Starting script.');

	// grab all elements with specific class of buttonContainer
	const buttonContainerElems =
		getElementsWithClassDespiteObfuscatedClassName('buttonContainer');

	const emojiButton = null;

	// for every button container element
	for (let i = 0; i < buttonContainerElems.length; ++i) {
		// get the current element
		const elem = buttonContainerElems[i];

		// get the children of the current element
		const children = elem.children;

		// loop through the children
		for (let j = 0; j < children.length; ++j) {
			// get the current child element
			const child = children[j];

			// get the class list of the current child element
			const classList = child.classList;

			// loop through the class list
			for

	// click the button
	emojiButton.click();

	// Wait for 5 seconds
	await waitForSeconds(3);
})();

Step 4: Open the emojis panel in any server or dm, it doesnt matter where or if you have nitro

Step 5: Run getEmojis() , repeat every 2 lines scrolling down

Step6: Switch to stickers tab and run getStickers(), repeat every 2 lines

Step 7: When your done, run listLinks() to list all the links

Step 6: Make a folder, in that folder make a file called urls.txt and paste in links

Step 7: Open Powershell in the folder and run this to download everything in their full original size

gc urls.txt | % {iwr $_ -outf $(split-path $_ -leaf)}

Your done, I reccomend to re-disable the console panel in Discord by removing the setting and restarting Discord.

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