LiltenBot / plugins /search-define.js
mrfrank-ofc's picture
Upload 63 files
8d8b0ad verified
raw
history blame
2.07 kB
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.");
}
});