error checking for dictionary

This commit is contained in:
Raven Scott 2022-09-25 02:50:27 -04:00
parent 42e7a234b3
commit 21d8446383
1 changed files with 18 additions and 4 deletions

View File

@ -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")