Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
646 B
2
Indexable
Never
from PyDictionary import PyDictionary

dictionary = PyDictionary()

async def get_dictionary_definition(interaction, word):
    definition = dictionary.meaning(word)
    if definition:
        formatted_definition = '\n'.join([f'**{key}**: {", ".join(val)}' for key, val in definition.items()])
        try:
            await interaction.response.send_message(content=f"Definition of '{word}':\n{formatted_definition}")
        except discord.errors.NotFound:
            print("Interaction not found. It may have expired.")
    else:
        await interaction.response.send_message(content=f"Sorry, I could not find a definition for '{word}'.")
Leave a Comment