From f5f92a4a698ed86b23cfd78867b0d49a2c9445a9 Mon Sep 17 00:00:00 2001 From: stavilam Date: Wed, 28 Nov 2018 00:16:38 +0000 Subject: [PATCH] Added comments, fixed styling, small performance improvements --- apiFunctionsFile.py | 261 +++++++++++++++++++++++++++++++------------- 1 file changed, 186 insertions(+), 75 deletions(-) diff --git a/apiFunctionsFile.py b/apiFunctionsFile.py index f1aa60e..4e9fe3f 100644 --- a/apiFunctionsFile.py +++ b/apiFunctionsFile.py @@ -1,39 +1,68 @@ from discord.ext import commands -from botClient import colorCode, weatherKey, timeKey, dictionaryId, dictionaryKey -import asyncio +from botClient import client, colorCode, weatherKey, timeKey, dictionaryId, dictionaryKey from datetime import datetime from pprint import pprint +import asyncio import discord import aiohttp import json import urllib import urllib.parse +"""Module for various API based functions, such as finding the weather and/or time in any city, searching the +meaning of any word that exists in the Oxford Dictionaries, as well as synonyms/antonyms and example sentences +for said word(s).""" + class ApiFunctions: def __init__(self, client): self.client = client + """Command for WEATHER INFORMATION in any City requested by the user""" + @commands.command(name='weather') + @commands.cooldown(2, 4, commands.BucketType.user) + async def weather_command(self, ctx, f_arg=' ', *args): + """Shows current weather for any city chosen by the user""" + try: + await ctx.message.delete() + except discord.HTTPException: + pass + """If the user doesn't specify a city""" + if f_arg == ' ': + await ctx.send('Please specify city. (``>weather city_name``)', delete_after=5) + return + + """If the city is separated into more words, e.g. New York, combine them so that the user doesn't have to type + "New York" or New_York """ + loc = f_arg + for arg in args: + loc = str(loc) + " " + str(arg) - @commands.command(aliases = ['weather']) - async def weather_command(self, ctx, loc = 'Tokyo'): + """Fetches the data from the openweathermap.org api""" async with aiohttp.ClientSession() as session: async with session.get(f'http://api.openweathermap.org/data/2.5/weather?q={loc}&APPID={weatherKey}')\ as weatherReq: weatherResp = json.loads(await weatherReq.text()) - async with session.get(f'http://api.timezonedb.com/v2.1/get-time-zone?key={timeKey}' - f'&format=json&by=position&lat={weatherResp["coord"]["lat"]}' - f'&lng={weatherResp["coord"]["lon"]}') as timeReq: + """Try to get information about the time as well""" + try: + async with session.get(f'http://api.timezonedb.com/v2.1/get-time-zone?key={timeKey}' + f'&format=json&by=position&lat={weatherResp["coord"]["lat"]}' + f'&lng={weatherResp["coord"]["lon"]}') as timeReq: - timeResp = json.loads(await timeReq.text()) - #pprint(timeResp) testing purposes + """If it works (and it always should unless the API site is offline), formats the date + and time so it's easier to read for the user""" + if timeReq.status == 200: + timeResp = json.loads(await timeReq.text()) + timeRespDatetime = datetime.strptime(timeResp['formatted'], '%Y-%m-%d %H:%M:%S') + timeFormat = "%X, %A" - if weatherReq.status == 200 and timeReq.status ==200: + except KeyError: + pass - celsius = round(weatherResp['main']['temp'] - 273.15,2) - timeFormat = "%X, %A" - timeRespDatetime = datetime.strptime(timeResp['formatted'], '%Y-%m-%d %H:%M:%S') + if weatherReq.status == 200: + """Converts temperature to celsius and start building the discord embed then send it.""" + celsius = round(weatherResp['main']['temp'] - 273.15, 2) embed = discord.Embed( title=f'Weather in {weatherResp["name"]}, {weatherResp["sys"]["country"]}', @@ -53,10 +82,12 @@ class ApiFunctions: embed.add_field(name='Winds', value='≈' + str(weatherResp['wind']['speed']) + ' m/s', inline=True) - - embed.add_field(name='Timezone', - value=f'{timeResp["abbreviation"]} ({timeRespDatetime.strftime(timeFormat)})', - inline=True) + try: + embed.add_field(name='Timezone', + value=f'{timeResp["abbreviation"]} ({timeRespDatetime.strftime(timeFormat)})', + inline=True) + except UnboundLocalError: + pass embed.set_thumbnail(url=f'http://openweathermap.org/img/w/{weatherResp["weather"][0]["icon"]}.png') embed.set_footer(text="Requested by " + ctx.message.author.name + '.', @@ -65,10 +96,33 @@ class ApiFunctions: await ctx.send(embed=embed) else: - print(f'Request failed: Weather status:{weatherReq.status}, Time status: {timeReq.status}') + await ctx.send(f"``{weatherReq.status}``: Couldn't get weather info for ``{loc}``.", delete_after=5) + print(f'Request failed: Weather status:{weatherReq.status}') + + """Command for TIME INFORMATION in any City requested by the user""" + @commands.command(name='time', aliases=['timezone', 'date', 'clock', 'worldtime', 'citytime', 'worldclock']) + @commands.cooldown(2, 4, commands.BucketType.user) + async def time_command(self, ctx, f_arg=' ', *args): + """Shows current time for any city chosen by the user""" + try: + await ctx.message.delete() + except discord.HTTPException: + pass + + """If the user doesn't specify a city""" + if f_arg == ' ': + await ctx.send('Please specify city. (``>time city_name``)', delete_after=5) + return + + """If the city is separated into more words, e.g. New York, combine them so that the user doesn't have to type + "New York" or New_York """ + loc = f_arg + for arg in args: + loc = str(loc) + " " + str(arg) - @commands.command(aliases = ['time', 'timezone', 'date', 'clock','worldtime','citytime', 'worldclock']) - async def worldtime_command(self, ctx, loc = 'Tokyo'): + """The free version of the time API doesn't allow search by city names, so in order to bypass this limitation + we use the weather API to find the latitude and longitude of the desired city, then input them into the + time API request.""" async with aiohttp.ClientSession() as session: async with session.get(f'http://api.openweathermap.org/data/2.5/weather?q={loc}&APPID={weatherKey}') \ as weatherReq: @@ -80,9 +134,11 @@ class ApiFunctions: f'&lng={weatherResp["coord"]["lon"]}') as timeReq: timeResp = json.loads(await timeReq.text()) except KeyError: - await ctx.send(f'City with name or coords "{loc}" not found.') + await ctx.send(f'City with name or position ``{loc}`` not found.', delete_after=5) return + """If both requests are successful, we do some more time conversions then start building the + discord embed using the data, after which we send it.""" if weatherReq.status == 200 and timeReq.status == 200: timeRespDatetime = datetime.strptime(timeResp['formatted'], '%Y-%m-%d %H:%M:%S') if timeResp["gmtOffset"] > 0: @@ -106,11 +162,13 @@ class ApiFunctions: embed.set_thumbnail(url=f'http://openweathermap.org/img/w/{weatherResp["weather"][0]["icon"]}.png') await ctx.send(embed=embed) else: + await ctx.send(f"``{timeReq.status}``: Couldn't get time info for ``{loc}``.", delete_after=5) print(f'API request failed: Weather status:{weatherReq.status}, Time status: {timeReq.status}') - - @commands.command(aliases = ['word', 'definition', 'meaning', 'wordmeaning','def', 'wdef', 'w']) - async def word_definition(self, ctx, f_arg, *args): + """Command for WORD DEFINITION/MEANING for any word chosen by the user""" + @commands.command(name='word', aliases=['worddef', 'definition', 'def', 'wordmeaning', 'meaning', 'wdef', 'w']) + @commands.cooldown(2, 4, commands.BucketType.user) + async def word_definition(self, ctx, f_arg=" ", *args): """Returns a detailed word definition from OxfordDictionaries Expected inputs: Uppercase or lowercase English word, with or with no space between. Examples: water, swim, hard disk. @@ -131,10 +189,29 @@ class ApiFunctions: return the error name and code to the user. """ + try: + await ctx.message.delete() + except discord.HTTPException: + pass + + """If no parameters are given, ask the user to type a word. If nothing is given in the next 5 seconds, return""" + if f_arg == " ": + await ctx.send("Please input the word you're searching for.", delete_after=5) + + def pred(m): + return m.author == ctx.message.author and m.channel == ctx.message.channel + try: + f_arg = await client.wait_for('message', check=pred, timeout=5) + word_id = f_arg.content + if f_arg.content == '>': + return + except asyncio.TimeoutError: + return + else: + word_id = f_arg """Combines inputs separated by spaces into a single word. Selects the language as English, converts the word in URL format in case it is needed for special characters""" - word_id = f_arg for arg in args: word_id = str(word_id) + " " + str(arg) lang = 'en' @@ -153,21 +230,23 @@ class ApiFunctions: f'/search/{lang}?q={word_id.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description=f'No similar words found. \n' - f'Make sure that **"{word_id.lower()}"** is a valid word.', + f'Check that **"{word_id.lower()}"** is a valid word.', color=colorCode[2] ) await ctx.send(embed=embed) return + """Try to get 4 more similar words""" for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description='Did you mean: \n' + str(altWord), color=colorCode[1] @@ -184,16 +263,16 @@ class ApiFunctions: """================END OF API REQUEST CHECK================""" wordResp = json.loads(await wordReq.text()) - #pprint (wordResp) #testing """ CHECK IF DEFINITION IS FOUND - If not, search the inflection of the word instead (and API Req. check it) - Example: Inflection of "swimming" or "swam" is "swim" + If not, search the original form of the word instead (and API Req. check it) + Example: Inflection of "swim" is "swimming" or "swam" """ - try: - wordDef = wordResp['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['definitions'][0] - except KeyError: + + """if no definition is found""" + if not wordResp['results'][0]['lexicalEntries'][0]['entries'][0]['senses'][0]['definitions'][0]: + """search for the non-inflected version""" async with session.get( f'https://od-api.oxforddictionaries.com/api/v1/inflections/{lang}/{word_id.lower()}') \ as wordLemmaReq: @@ -205,18 +284,22 @@ class ApiFunctions: f'/search/{lang}?q={word_id.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description=f'No similar words found. \n' - f'Make sure that **"{word_id.lower()}"** is a valid word.', + f'Check that **"{word_id.lower()}"** ' + f'is a valid word.', color=colorCode[2] ) await ctx.send(embed=embed) return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}]" \ + f"(https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break # print(altWord) #testing @@ -228,7 +311,8 @@ class ApiFunctions: return elif wordLemmaReq.status != 200: embed = discord.Embed(title='Something went wrong', - description=f'Error: {wordLemmaReq.reason} \nCode: {wordLemmaReq.status}', + description=f'Error: {wordLemmaReq.reason} \n' + f'Code: {wordLemmaReq.status}', color=colorCode[2]) await ctx.send(embed=embed) return @@ -236,7 +320,6 @@ class ApiFunctions: """================END OF API REQUEST CHECK================""" wordLemmaResp = json.loads(await wordLemmaReq.text()) - # pprint (wordLemmaResp) #testing wordLemmaId = wordLemmaResp['results'][0]['lexicalEntries'][0]['inflectionOf'][0]['id'] async with session.get( f'https://od-api.oxforddictionaries.com/api/v1/entries/{lang}/{wordLemmaId.lower()}') \ @@ -290,9 +373,15 @@ class ApiFunctions: """==================BUILDING THE DISCORD EMBED END==================""" await ctx.send(embed=embed) - @commands.command(aliases = ['synonym', 'wordsynonym', 'ws', 'syn']) - async def word_synonym(self, ctx, f_arg, *args): + """Command for WORD SYNONYM for any word chosen by the user""" + @commands.command(aliases=['synonym', 'wordsynonym', 'ws', 'syn']) + @commands.cooldown(2, 4, commands.BucketType.user) + async def word_synonym(self, ctx, f_arg="word", *args): """Returns a list of synonyms for the inputted word.""" + try: + await ctx.message.delete() + except discord.HTTPException: + pass word_id = f_arg for arg in args: word_id = str(word_id) + " " + str(arg) @@ -308,7 +397,8 @@ class ApiFunctions: f'/search/{lang}?q={word_id.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description=f'No similar words found. \n' @@ -319,10 +409,10 @@ class ApiFunctions: return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing embed = discord.Embed(title=f'Could not find synonyms for the word "{word_id.lower()}."', description='Similar words: \n' + str(altWord), color=colorCode[1] @@ -339,7 +429,8 @@ class ApiFunctions: wordLemmaResp = json.loads(await wordLemmaReq.text()) wordLemmaId = wordLemmaResp['results'][0]['lexicalEntries'][0]['inflectionOf'][0]['id'] - async with session.get(f'https://od-api.oxforddictionaries.com/api/v1/entries/{lang}/{wordLemmaId.lower()}/synonyms') \ + async with session.get(f'https://od-api.oxforddictionaries.com/api/v1/entries/' + f'{lang}/{wordLemmaId.lower()}/synonyms') \ as wordReq: """==============START OF API REQUEST CHECK==============""" @@ -348,21 +439,23 @@ class ApiFunctions: f'/search/{lang}?q={wordLemmaId.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{wordLemmaId.lower()}."', description=f'No similar words found. \n' - f'Make sure that **"{wordLemmaId.lower()}"** is a valid word.', + f'Make sure that **"{wordLemmaId.lower()}"**' + f' is a valid word.', color=colorCode[2] ) await ctx.send(embed=embed) return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing embed = discord.Embed(title=f'Could not find synonyms for the word "{wordLemmaId.lower()}."', description='You could try these words instead: \n' + str(altWord), color=colorCode[1] @@ -378,7 +471,6 @@ class ApiFunctions: """===============END OF API REQUEST CHECK===============""" wordResp = json.loads(await wordReq.text()) - #pprint(wordResp) #testing """=================BUILDING THE DISCORD EMBED START=================""" """Will attempt to give two different contexts (with an example sentence) with 3 synonyms each""" @@ -434,9 +526,15 @@ class ApiFunctions: await ctx.send(embed=embed) - @commands.command(aliases = ['antonym', 'wordantonym', 'wa', 'ant']) - async def word_antonym(self, ctx, f_arg, *args): + """Command for WORD ANTONYM for any word chosen by the user""" + @commands.command(aliases=['antonym', 'wordantonym', 'wa', 'ant']) + @commands.cooldown(2, 4, commands.BucketType.user) + async def word_antonym(self, ctx, f_arg="identical", *args): """Returns a list of antonyms for the inputted word.""" + try: + await ctx.message.delete() + except discord.HTTPException: + pass word_id = f_arg for arg in args: word_id = str(word_id) + " " + str(arg) @@ -452,7 +550,8 @@ class ApiFunctions: f'/search/{lang}?q={word_id.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description=f'No similar words found. \n' @@ -463,10 +562,10 @@ class ApiFunctions: return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing embed = discord.Embed(title=f'Could not find antonyms for the word "{word_id.lower()}."', description='Similar words: \n' + str(altWord), color=colorCode[1] @@ -483,7 +582,8 @@ class ApiFunctions: wordLemmaResp = json.loads(await wordLemmaReq.text()) wordLemmaId = wordLemmaResp['results'][0]['lexicalEntries'][0]['inflectionOf'][0]['id'] - async with session.get(f'https://od-api.oxforddictionaries.com/api/v1/entries/{lang}/{wordLemmaId.lower()}/antonyms') \ + async with session.get(f'https://od-api.oxforddictionaries.com/api/v1/entries/' + f'{lang}/{wordLemmaId.lower()}/antonyms') \ as wordReq: """==============START OF API REQUEST CHECK==============""" @@ -492,21 +592,23 @@ class ApiFunctions: f'/search/{lang}?q={wordLemmaId.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{wordLemmaId.lower()}."', description=f'No similar words found. \n' - f'Make sure that **"{wordLemmaId.lower()}"** is a valid word.', + f'Make sure that **"{wordLemmaId.lower()}"** ' + f'is a valid word.', color=colorCode[2] ) await ctx.send(embed=embed) return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing embed = discord.Embed(title=f'Could not find antonyms for the word "{wordLemmaId.lower()}."', description='Similar words: \n' + str(altWord), color=colorCode[1] @@ -577,9 +679,15 @@ class ApiFunctions: await ctx.send(embed=embed) - @commands.command(aliases = ['sentence', 'sentences', 'wsen', 'sen', 'wordsentence', 'example', 'wordexample']) - async def word_sentences(self, ctx, f_arg, *args): + """Command for EXAMPLE SENTENCES with a word chosen by the user""" + @commands.command(aliases=['sentence', 'sentences', 'wsen', 'sen', 'wordsentence', 'example', 'wordexample']) + @commands.cooldown(2, 4, commands.BucketType.user) + async def word_sentences(self, ctx, f_arg="word", *args): """Returns a list of example sentences for the inputted word.""" + try: + await ctx.message.delete() + except discord.HTTPException: + pass word_id = f_arg for arg in args: word_id = str(word_id) + " " + str(arg) @@ -595,7 +703,8 @@ class ApiFunctions: f'/search/{lang}?q={word_id.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', description=f'No similar words found. \n' @@ -606,12 +715,12 @@ class ApiFunctions: return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing - embed = discord.Embed(title=f'Could not find the word "{word_id.lower()}."', - description='Did you mean: \n' + str(altWord), + embed = discord.Embed(title=f'Could not find any sentences for the word "{word_id.lower()}."', + description='You can try searching for: \n' + str(altWord), color=colorCode[1] ) await ctx.send(embed=embed) @@ -636,23 +745,25 @@ class ApiFunctions: f'/search/{lang}?q={wordLemmaId.lower()}&prefix=false') as searchReq: searchResp = json.loads(await searchReq.text()) try: - altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][0]['id']}) \n" + altWord = f"[{searchResp['results'][0]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][0]['id']}) \n" except IndexError: embed = discord.Embed(title=f'Could not find the word "{wordLemmaId.lower()}."', description=f'No similar words found. \n' - f'Make sure that **"{wordLemmaId.lower()}"** is a valid word.', + f'Make sure that **"{wordLemmaId.lower()}"** ' + f'is a valid word.', color=colorCode[2] ) await ctx.send(embed=embed) return for i in range(1, 5): try: - altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com/definition/{searchResp['results'][i]['id']}) \n" + altWord += f"[{searchResp['results'][i]['id']}](https://en.oxforddictionaries.com" \ + f"/definition/{searchResp['results'][i]['id']}) \n" except IndexError: break - # print(altWord) #testing - embed = discord.Embed(title=f'Could not find the word "{wordLemmaId.lower()}."', - description='Did you mean: \n' + str(altWord), + embed = discord.Embed(title=f'Could not find any sentences for the word "{wordLemmaId.lower()}."', + description='You can try searching for: \n' + str(altWord), color=colorCode[1] ) await ctx.send(embed=embed) @@ -666,7 +777,7 @@ class ApiFunctions: """===============END OF API REQUEST CHECK===============""" wordResp = json.loads(await wordReq.text()) - pprint(wordResp) #testing + #pprint(wordResp) #testing """=================BUILDING THE DISCORD EMBED START=================""" """Will attempt to give two different contexts (with an example sentence) with 3 synonyms each"""