├── requirements.txt ├── README.md └── cheggDcBot.py /requirements.txt: -------------------------------------------------------------------------------- 1 | requests==2.24.0 2 | discord.py==1.5.1 3 | beautifulsoup4==4.9.3 4 | discord==1.0.1 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | :bangbang: This code no longer works. Working code is now private. :bangbang: 2 | 3 | 4 | # Chegg-Discord-Bot 5 | Chegg bot for Discord. 6 | You can access chegg answers via discord. 7 | 8 | ## Setup: 9 | You must set your `ID TOKEN` , `USER AGENT` and `BOT TOKEN`. 10 | 11 | - [x] Get text answers 12 | - [x] Get image answers 13 | - [x] Send the answer privately 14 | 15 | ## Run: 16 | 17 | `cd Chegg-Discord-Bot` 18 | 19 | `pip3 install -r requirements.txt` 20 | 21 | `python3 cheggDcBot.py` 22 | 23 | 24 | Demo video link : https://streamable.com/0ix1wj 25 | 26 | 27 | 28 | ### Bitcoin wallet: 29 | > 3NFfd1QXUVFsZzfbwGJiAJdehtPB9D88tK 30 | -------------------------------------------------------------------------------- /cheggDcBot.py: -------------------------------------------------------------------------------- 1 | ##################################### 2 | # https://github.com/T4WW 3 | # https://github.com/alpkeskin 4 | 5 | ##################################### 6 | import os 7 | import discord, re, requests, asyncio 8 | from discord.ext import commands 9 | from bs4 import BeautifulSoup 10 | 11 | bot = discord.Client() 12 | 13 | @bot.event 14 | async def on_ready(): 15 | 16 | guild_count = 0 17 | for guild in bot.guilds: 18 | print(f"- {guild.id} (name: {guild.name})") 19 | guild_count = guild_count + 1 20 | print("BOT is in " + str(guild_count) + " guilds.") 21 | 22 | @bot.event 23 | async def on_message(message): 24 | 25 | link = re.findall(r'(https?://[^\s]+)', message.content) 26 | check = '-ch ' + link[0] 27 | 28 | if(message.content == check): 29 | chegglink = link[0] 30 | try: 31 | if(chegglink[0:22] == "https://www.chegg.com/"): 32 | userRequest = requests.get(link[0],headers={"user-agent":"SET YOUR USER AGENT HERE", 33 | "accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,/;q=0.8,application/signed-exchange;v=b3;q=0.9", 34 | "cookie":"id_token= SET ID TOKEN HERE"}) 35 | source = BeautifulSoup(userRequest.content,"html") 36 | dmain = source.find("div",attrs={"class":"answer-given-body ugc-base"}) 37 | images = dmain.findAll('img') 38 | for image in images: 39 | await message.author.send(image['src']) 40 | await message.author.send('-----------------------------------------------------') 41 | data = source.find("div",attrs={"class":"answer-given-body ugc-base"}).text 42 | file = open('answer.txt', 'w') 43 | file.write(data) 44 | file.close() 45 | my_files = [discord.File('answer.txt')] 46 | print(link[0]) 47 | await message.author.send(files=my_files) 48 | exit(0) 49 | else: 50 | print("Link is not valid.") 51 | except ValueError: 52 | print("Unexpected value is given") 53 | exit(1) 54 | except ConnectionError as ex: 55 | raise RuntimeError('Failed to establish connection to the given soruce') from ex 56 | 57 | 58 | bot.run("!!! SET YOUR BOT TOKEN HERE !!!") 59 | --------------------------------------------------------------------------------