Skip to content

Instantly share code, notes, and snippets.

@peterthehan
Last active March 20, 2022 04:43
Show Gist options
  • Save peterthehan/b79cc31f23aaa89e3847440d1fe69ba4 to your computer and use it in GitHub Desktop.
Save peterthehan/b79cc31f23aaa89e3847440d1fe69ba4 to your computer and use it in GitHub Desktop.
Batch download emojis from any Discord server.
// 0. Open Discord's web client
// 1. Visit the server whose emojis you want
// 2. Open the emoji picker UI and keep it open
// 3. Minimize the page's zoom so that as many emojis load into the picker as possible
// 4. Open the browser's DevTools (press F12) > Elements tab
// 5. Search for the class "categorySection" e.g. <div class="categorySection-...">
// 6. Find the section that highlights the emojis you want when hovering over the element
// 7. Right click the element and Copy > Copy Element
// 8. Paste the element into a file "file.txt"
// 9. Run this script at the same location as "file.txt" to download all the emojis.
// Use a sensible sleep value so as not to rate-limit yourself
// The script relies on scraping so the regexp/logic may become outdated
const https = require("https");
const fs = require("fs");
const sleepDuration = 1000;
const emojiRegExp = /<li.*?<img.*?><\/li>/g;
const emojiNameRegExp = /alt=":(\w+?):"/;
const emojiUrlRegExp = /src="(.*?)"/;
const classNameRegExp = /class="(.*?)"/;
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const main = async () => {
const input = fs.readFileSync("./file.txt").toString();
const parsed = [...input.matchAll(emojiRegExp)]
.map((match) => match[0])
.map((fragment) => {
const emojiName = fragment.match(emojiNameRegExp)[1];
const emojiUrl = fragment.match(emojiUrlRegExp)[1];
const className = fragment.match(classNameRegExp)[1];
const isAnimated = className.includes("emojiItemDisabled");
return isAnimated
? {
emojiName,
extension: "gif",
emojiUrl: emojiUrl.replace("png", "gif"),
}
: { emojiName, extension: "png", emojiUrl };
});
for (const { emojiName, extension, emojiUrl } of parsed) {
const file = fs.createWriteStream(`./${emojiName}.${extension}`);
https.get(emojiUrl, function (response) {
response.pipe(file);
});
await sleep(sleepDuration);
}
};
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment