Skip to content

Instantly share code, notes, and snippets.

@miou-gh
Created February 10, 2021 03:25
Show Gist options
  • Save miou-gh/8bd8170fea4f0f8cdc725e4e44b10d95 to your computer and use it in GitHub Desktop.
Save miou-gh/8bd8170fea4f0f8cdc725e4e44b10d95 to your computer and use it in GitHub Desktop.
import discord
import asyncio
import os
import time
import sys
import cloudscraper
from PIL import Image
from io import BytesIO
# get character encoding for printing to the terminal
encoding = sys.stdout.encoding
# create scraper
scraper = cloudscraper.create_scraper()
# create a client
client = discord.Client()
# create a folder for storing the emojis
if not os.path.exists('Emojis'):
os.makedirs('Emojis')
@client.event
async def on_ready():
print('Logged in as \"%s\" with ID %s' % (client.user.name, client.user.id))
print('Connected guilds:')
for guild in client.guilds:
# print out guild names and number of emojis
print('\t%s (%s)' % (str(guild.name).encode(encoding, 'replace').decode(encoding), guild.id))
emoji_count = len(guild.emojis)
print('\t\tEmoji Count: %s' % emoji_count)
# make a folder for each folder if it actually has emojis, striping out invalid characters
folder_name = 'Emojis\\' + guild.name.translate({ord(c): None for c in '/<>:"\\|?*'})
if emoji_count > 0:
if not os.path.exists(folder_name):
os.makedirs(folder_name)
# download the emojis
print('\t\tDownloading emojis...')
for emoji in guild.emojis:
# create a file name
if emoji.animated:
file_name = folder_name + '\\' + emoji.name + '.gif'
else:
file_name = folder_name + '\\' + emoji.name + '.png'
# download if we dont already have it
if not os.path.exists(file_name):
r = scraper.get(emoji.url)
i = Image.open(BytesIO(r.content))
i.save(file_name)
time.sleep(0.1)
print('All done!')
await client.logout()
if len(sys.argv) == 2:
try:
client.run(sys.argv[1], bot=False)
except discord.LoginFailure:
print('login failure (1)')
client.logout()
elif len(sys.argv) == 3:
try:
client.run(sys.argv[1], sys.argv[2])
except discord.LoginFailure:
print('login failure (2)')
else:
print('Invalid number of arguments. If using 2FA, your token is required. '
'Otherwise, provide your email and password. See https://github.com/qwertyboy/emoji-dumper'
' for more details.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment