diff --git a/commands/untils/dictionary.js b/commands/untils/dictionary.js index 094aed2..f3b7f46 100644 --- a/commands/untils/dictionary.js +++ b/commands/untils/dictionary.js @@ -5,9 +5,11 @@ const { AttachmentBuilder } = require('discord.js'); var download = require('download-file') - +const isNotDefined = require("is-not-defined"); +let phonetic var unirest = require('unirest'); let meaningsArray = [] + module.exports = { name: "dictionary", description: "Returns information about a word", @@ -28,10 +30,22 @@ module.exports = { 'Content-Type': 'application/json', }) .then((response) => { - let data = response.body[0] - let audio = data.phonetics[0].audio - let phonetic = data.phonetics[1].text + let data = response.body[0] + + if (isNotDefined(data)){ + + return interaction.editReply("Sorry, nothing was found!") + } + + if (isNotDefined(data.phonetics[1])){ + phonetic = "" + } else { + phonetic = data.phonetics[1].text + + } + + let audio = data.phonetics[0].audio if (!audio) { const embed = new EmbedBuilder() .setColor("#FF0000")