@@ -352,11 +352,51 @@ async def eight_ball(self, context: Context, *, question: str) -> None:
352
352
async def support (self , context : commands .Context ) -> None :
353
353
message = await context .send ("https://discord.gg/wtur9j8uVP" )
354
354
355
+ @commands .hybrid_command (
356
+ name = "define" ,
357
+ description = "Get the definition of a word." ,
358
+ usage = "define <word>" ,
359
+ aliases = ["dictionary" ]
360
+ )
361
+ @commands .check (Checks .is_not_blacklisted )
362
+ @commands .check (Checks .command_not_disabled )
363
+ @app_commands .allowed_installs (guilds = True , users = True )
364
+ @app_commands .allowed_contexts (guilds = True , dms = True , private_channels = True )
365
+ async def define (self , context : Context , * , word : str ) -> None :
366
+ async with aiohttp .ClientSession () as session :
367
+ async with session .get (f"https://api.dictionaryapi.dev/api/v2/entries/en/{ word } " ) as response :
368
+ if response .status != 200 :
369
+ return await context .send ("No results found." )
370
+
371
+ data = await response .json ()
372
+ data = data [0 ]
373
+
374
+ embed = discord .Embed (title = f"Definition of { data ['word' ]} " , description = data .get ("phonetic" , "N/A" ), color = 0xBEBEFE )
375
+
376
+ def truncate_text (text , limit = 1024 ):
377
+ if len (text ) > limit :
378
+ return text [:limit - 3 ] + "..."
379
+ return text
380
+
381
+ definitions = "\n " .join (f"{ i + 1 } . { definition ['definition' ]} " for i , meaning in enumerate (data ["meanings" ]) for definition in meaning ["definitions" ])
382
+
383
+ synonyms = ", " .join (synonym for meaning in data ["meanings" ] for synonym in meaning .get ("synonyms" , []))
384
+ antonyms = ", " .join (antonym for meaning in data ["meanings" ] for antonym in meaning .get ("antonyms" , []))
385
+
386
+ embed .add_field (name = "Definition(s)" , value = truncate_text (definitions ), inline = False )
387
+ embed .add_field (name = "Synonym(s)" , value = truncate_text (synonyms ) if synonyms else "None" , inline = False )
388
+ embed .add_field (name = "Antonym(s)" , value = truncate_text (antonyms ) if antonyms else "None" , inline = False )
389
+
390
+ await context .send (embed = embed )
391
+
392
+
393
+
394
+
355
395
@commands .hybrid_command (
356
396
name = "urban-dictionary" ,
357
397
description = "Get the definition of a word from Urban Dictionary." ,
358
398
usage = "urban-dictionary <word>" ,
359
- aliases = ["urban" ]
399
+ aliases = ["urban" , "ud" ]
360
400
)
361
401
@commands .check (Checks .is_not_blacklisted )
362
402
@commands .check (Checks .command_not_disabled )
0 commit comments