Spaces:
Runtime error
Runtime error
File size: 2,069 Bytes
8d8b0ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
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}
> *@ Powered By SubZero*`;
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.");
}
});
|