async def googleimage(self, ctx, *, search): """returns an image based on your search from google""" url = "https://www.googleapis.com/customsearch/v1?key=" + Token.google( ) + "&cx=014023765838117903829:klo2euskkae&searchType=image&{}".format( urllib.parse.urlencode({"q": search})) request = Request(url) data = json.loads(urlopen(request).read().decode()) s = discord.Embed() s.set_author( name="Google", icon_url= "https://images-ext-1.discordapp.net/external/UsMM0mPPHEKn6WMst8WWG9qMCX_A14JL6Izzr47ucOk/http/i.imgur.com/G46fm8J.png", url="https://www.google.co.uk/search?{}".format( urllib.parse.urlencode({"q": search}))) try: s.set_image(url=data["items"][0]["image"]["thumbnailLink"]) except: await ctx.send("No results :no_entry:") return await ctx.send(embed=s)
async def google(self, ctx, *, search): """returns the top 5 results from google of your search query""" url = "https://www.googleapis.com/customsearch/v1?key=" + Token.google( ) + "&cx=014023765838117903829:mm334tqd3kg&{}".format( urllib.parse.urlencode({"q": search})) request = Request(url) data = json.loads(urlopen(request).read().decode()) try: results = "\n\n".join([ "**[{}]({})**\n{}".format(x["title"], x["link"], x["snippet"]) for x in data["items"] ][:5]) except: await ctx.send("No Results :no_entry:") return s = discord.Embed(description=results) s.set_author( name="Google", icon_url= "https://images-ext-1.discordapp.net/external/UsMM0mPPHEKn6WMst8WWG9qMCX_A14JL6Izzr47ucOk/http/i.imgur.com/G46fm8J.png", url="https://www.google.co.uk/search?{}".format( urllib.parse.urlencode({"q": search}))) await ctx.send(embed=s)