Skip to content

Commit cc80863

Browse files
author
Cyteon
committed
add proper dictionary
1 parent 0d364c8 commit cc80863

File tree

2 files changed

+42
-2
lines changed

2 files changed

+42
-2
lines changed

bot.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def __init__(self) -> None:
9393
)
9494
self.logger = logger
9595
self.config = config
96-
self.version = "2.1.4"
96+
self.version = "2.1.5"
9797
self.start_time = time.time()
9898
self.prefixDB = prefixDB
9999
self.statsDB = statsDB

cogs/general.py

+41-1
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,51 @@ async def eight_ball(self, context: Context, *, question: str) -> None:
352352
async def support(self, context: commands.Context) -> None:
353353
message = await context.send("https://discord.gg/wtur9j8uVP")
354354

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+
355395
@commands.hybrid_command(
356396
name="urban-dictionary",
357397
description="Get the definition of a word from Urban Dictionary.",
358398
usage="urban-dictionary <word>",
359-
aliases=["urban"]
399+
aliases=["urban", "ud"]
360400
)
361401
@commands.check(Checks.is_not_blacklisted)
362402
@commands.check(Checks.command_not_disabled)

0 commit comments

Comments
 (0)