From d5db08e6ac5fa29804aa22cb1e5671e4131966d9 Mon Sep 17 00:00:00 2001 From: stijndcl Date: Tue, 27 Sep 2022 11:32:19 +0200 Subject: [PATCH] Show error message if no definitions are found --- didier/cogs/other.py | 6 +++++- didier/data/embeds/urban_dictionary.py | 9 +++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/didier/cogs/other.py b/didier/cogs/other.py index fac1a04..02c0095 100644 --- a/didier/cogs/other.py +++ b/didier/cogs/other.py @@ -9,6 +9,7 @@ from database.schemas import Link from didier import Didier from didier.data.apis import disease_sh, inspirobot, urban_dictionary from didier.data.embeds.google import GoogleSearch +from didier.data.embeds.urban_dictionary import Definition from didier.data.scrapers import google 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.""" async with ctx.typing(): 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") @app_commands.describe(query="Search query") diff --git a/didier/data/embeds/urban_dictionary.py b/didier/data/embeds/urban_dictionary.py index 3126fed..6dfeaac 100644 --- a/didier/data/embeds/urban_dictionary.py +++ b/didier/data/embeds/urban_dictionary.py @@ -59,3 +59,12 @@ class Definition(EmbedPydantic): embed.add_field(name="Link", value=f"[Urban Dictionary]({self.permalink})", inline=True) 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