Show error message if no definitions are found

pull/136/head
stijndcl 2022-09-27 11:32:19 +02:00
parent 105cee7e6e
commit d5db08e6ac
2 changed files with 14 additions and 1 deletions

View File

@ -9,6 +9,7 @@ from database.schemas import Link
from didier import Didier from didier import Didier
from didier.data.apis import disease_sh, inspirobot, urban_dictionary from didier.data.apis import disease_sh, inspirobot, urban_dictionary
from didier.data.embeds.google import GoogleSearch from didier.data.embeds.google import GoogleSearch
from didier.data.embeds.urban_dictionary import Definition
from didier.data.scrapers import google from didier.data.scrapers import google
from didier.utils.discord.autocompletion.country import autocomplete_country from didier.utils.discord.autocompletion.country import autocomplete_country
@ -49,7 +50,10 @@ class Other(commands.Cog):
"""Look up the definition of `query` on the Urban Dictionary.""" """Look up the definition of `query` on the Urban Dictionary."""
async with ctx.typing(): async with ctx.typing():
definitions = await urban_dictionary.lookup(self.client.http_session, query) definitions = await urban_dictionary.lookup(self.client.http_session, query)
await ctx.reply(embed=definitions[0].to_embed(), mention_author=False) await ctx.reply(
embed=definitions[0].to_embed() if definitions else Definition.no_result_found_embed(),
mention_author=False,
)
@commands.hybrid_command(name="google", description="Google search") @commands.hybrid_command(name="google", description="Google search")
@app_commands.describe(query="Search query") @app_commands.describe(query="Search query")

View File

@ -59,3 +59,12 @@ class Definition(EmbedPydantic):
embed.add_field(name="Link", value=f"[Urban Dictionary]({self.permalink})", inline=True) embed.add_field(name="Link", value=f"[Urban Dictionary]({self.permalink})", inline=True)
return embed return embed
@staticmethod
def no_result_found_embed() -> discord.Embed:
"""Embed shown when no definitions could be found"""
embed = discord.Embed(title="Urban Dictionary", colour=colours.error_red())
embed.description = "No definitions could be found."
return embed