Bug Fix: Fixing Dictionary not loading on some words

This commit is contained in:
Raven Scott 2022-09-25 06:27:01 -04:00
parent d85912e80d
commit 47cb0dba9a
1 changed files with 20 additions and 3 deletions

View File

@ -31,12 +31,12 @@ module.exports = {
})
.then((response) => {
let data = response.body[0]
console.log(data.meanings)
if (isNotDefined(data)) {
return interaction.editReply("Sorry, nothing was found!")
}
if (isNotDefined(data.phonetics[1])) {
if (isNotDefined(data.phonetics)) {
phonetic = ""
} else {
phonetic = data.phonetics[1].text
@ -44,6 +44,22 @@ module.exports = {
let audio = data.phonetics[0].audio
if (!audio) {
data.meanings.forEach(wordData => {
if (wordData.definitions[0].example) {
meaningsArray.push({
"name": wordData.partOfSpeech,
"value": wordData.definitions[0].definition + "\nExample: " + wordData.definitions[0].example
})
} else {
meaningsArray.push({
"name": wordData.partOfSpeech,
"value": wordData.definitions[0].definition
})
}
});
const embed = new EmbedBuilder()
.setColor("#FF0000")
.setTitle("Results for " + word + ": " + phonetic)
@ -68,7 +84,7 @@ module.exports = {
download(audio, options, function(err) {
if (err) throw err
console.log("audio downloaded")
console.log(response.body)
console.log(data.meanings)
data.meanings.forEach(wordData => {
if (wordData.definitions[0].example) {
@ -83,6 +99,7 @@ module.exports = {
})
}
});
console.log(data)
const file = new AttachmentBuilder('./audio/' + rand + ".mp3");