| const axios = require('axios'); | |
| const {cmd , commands} = require('../command'); | |
| cmd({ | |
| pattern: "define", | |
| desc: "π Get the definition of a word", | |
| react: "π", | |
| category: "Auther", | |
| filename: __filename | |
| }, | |
| async (conn, mek, m, { from, q, reply }) => { | |
| try { | |
| if (!q) return reply("β Please provide a word to define. Usage: .define [word]"); | |
| const word = q; | |
| const url = `https://api.dictionaryapi.dev/api/v2/entries/en/${word}`; | |
| const response = await axios.get(url); | |
| const definitionData = response.data[0]; | |
| const definition = definitionData.meanings[0].definitions[0].definition; | |
| const example = definitionData.meanings[0].definitions[0].example || 'No example available'; | |
| const synonyms = definitionData.meanings[0].definitions[0].synonyms.join(', ') || 'No synonyms available'; | |
| const wordInfo = ` | |
| π *Word*: ${definitionData.word} | |
| π *Definition*: ${definition} | |
| π *Example*: ${example} | |
| π *Synonyms*: ${synonyms} | |
| *MADE WITH β₯ ALI-MD*`; | |
| return reply(wordInfo); | |
| } catch (e) { | |
| console.log(e); | |
| if (e.response && e.response.status === 404) { | |
| return reply("π« Word not found. Please check the spelling and try again."); | |
| } | |
| return reply("β οΈ An error occurred while fetching the definition. Please try again later."); | |
| } | |
| }); | |