error checking for dictionary

This commit is contained in:
Raven Scott 2022-09-25 02:50:27 -04:00
parent 42e7a234b3
commit 21d8446383

View File

@ -5,9 +5,11 @@ const {
AttachmentBuilder AttachmentBuilder
} = require('discord.js'); } = require('discord.js');
var download = require('download-file') var download = require('download-file')
const isNotDefined = require("is-not-defined");
let phonetic
var unirest = require('unirest'); var unirest = require('unirest');
let meaningsArray = [] let meaningsArray = []
module.exports = { module.exports = {
name: "dictionary", name: "dictionary",
description: "Returns information about a word", description: "Returns information about a word",
@ -28,10 +30,22 @@ module.exports = {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
}) })
.then((response) => { .then((response) => {
let data = response.body[0] let data = response.body[0]
let audio = data.phonetics[0].audio
let phonetic = data.phonetics[1].text 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) { if (!audio) {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setColor("#FF0000") .setColor("#FF0000")