From 539d25ac11a2b4d6fc74f7e8d83fd3f949477fff Mon Sep 17 00:00:00 2001 From: Sultan Iskandar Maulana Date: Sat, 6 Apr 2024 16:05:59 +0000 Subject: [PATCH] Fix Urban Dictionary failing creating embed --- classes/urbandictionary.py | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/classes/urbandictionary.py b/classes/urbandictionary.py index e0ca6546..64a93848 100644 --- a/classes/urbandictionary.py +++ b/classes/urbandictionary.py @@ -36,7 +36,7 @@ class UrbanDictionaryEntry: """Current vote""" written_on: datetime """Date written on""" - example: str + example: str | None """Example of the word""" thumbs_down: int """Number of thumbs down""" @@ -59,11 +59,12 @@ def embed(self) -> Embed: description=f"{self.definition}", color=0x1b2936, ) - embed.add_field( - name="Example", - value=self.example, - inline=False, - ) + if self.example: + embed.add_field( + name="Example", + value=self.example, + inline=False, + ) embed.add_field( name="Author", value=self.author, @@ -74,9 +75,12 @@ def embed(self) -> Embed: url="https://www.urbandictionary.com/", ) # percentage of thumbs up - percentage = round( - (self.thumbs_up / (self.thumbs_up + self.thumbs_down)) * 100 - ) + try: + percentage = round( + (self.thumbs_up / (self.thumbs_up + self.thumbs_down)) * 100 + ) + except ZeroDivisionError: + percentage = 0 embed.set_footer( text=f"👍 {self.thumbs_up} / 👎 {self.thumbs_down} ({percentage}%), page {self.current}/{self.total_pages}" )