88 lines
3.2 KiB
JavaScript
88 lines
3.2 KiB
JavaScript
|
const {
|
||
|
EmbedBuilder
|
||
|
} = require('discord.js');
|
||
|
const {
|
||
|
AttachmentBuilder
|
||
|
} = require('discord.js');
|
||
|
var download = require('download-file')
|
||
|
|
||
|
var unirest = require('unirest');
|
||
|
let meaningsArray = []
|
||
|
module.exports = {
|
||
|
name: "dictionary",
|
||
|
description: "Returns information about a word",
|
||
|
options: [{
|
||
|
"name": "word",
|
||
|
"description": "The data you would like inside of the QR",
|
||
|
"required": true,
|
||
|
"type": 3 // 6 is type USER
|
||
|
}],
|
||
|
run: async (client, interaction) => {
|
||
|
let rand = Math.floor(Math.random() * 99999).toString();
|
||
|
let word = interaction.options._hoistedOptions[0].value
|
||
|
|
||
|
unirest
|
||
|
.get('https://api.dictionaryapi.dev/api/v2/entries/en/' + word)
|
||
|
.headers({
|
||
|
'Accept': 'application/json',
|
||
|
'Content-Type': 'application/json',
|
||
|
})
|
||
|
.then((response) => {
|
||
|
let data = response.body[0]
|
||
|
let audio = data.phonetics[0].audio
|
||
|
let phonetic = data.phonetics[1].text
|
||
|
|
||
|
if (!audio) {
|
||
|
const embed = new EmbedBuilder()
|
||
|
.setColor("#FF0000")
|
||
|
.setTitle("Results for " + word + ": " + phonetic)
|
||
|
.addFields(meaningsArray)
|
||
|
.setTimestamp()
|
||
|
.setFooter({
|
||
|
text: `Requested by ${interaction.user.tag}`,
|
||
|
iconURL: `${interaction.user.displayAvatarURL()}`
|
||
|
});
|
||
|
interaction.editReply({
|
||
|
embeds: [embed]
|
||
|
});
|
||
|
rand = Math.floor(Math.random() * 99999).toString();
|
||
|
} else {
|
||
|
// Options for Audio Download
|
||
|
var options = {
|
||
|
directory: "./audio/",
|
||
|
filename: rand + ".mp3"
|
||
|
}
|
||
|
|
||
|
download(audio, options, function(err) {
|
||
|
if (err) throw err
|
||
|
console.log("audio downloaded")
|
||
|
console.log(response.body)
|
||
|
data.meanings.forEach(wordData => {
|
||
|
meaningsArray.push({
|
||
|
"name": wordData.partOfSpeech,
|
||
|
"value": wordData.definitions[0].definition
|
||
|
})
|
||
|
});
|
||
|
|
||
|
const file = new AttachmentBuilder('./audio/' + rand + ".mp3");
|
||
|
|
||
|
const embed = new EmbedBuilder()
|
||
|
.setColor("#FF0000")
|
||
|
.setTitle("Results for " + word + ": " + phonetic)
|
||
|
.addFields(meaningsArray)
|
||
|
.setTimestamp()
|
||
|
.setFooter({
|
||
|
text: `Requested by ${interaction.user.tag}`,
|
||
|
iconURL: `${interaction.user.displayAvatarURL()}`
|
||
|
});
|
||
|
interaction.editReply({
|
||
|
embeds: [embed],
|
||
|
files: [file]
|
||
|
});
|
||
|
rand = Math.floor(Math.random() * 99999).toString();
|
||
|
})
|
||
|
}
|
||
|
})
|
||
|
|
||
|
},
|
||
|
};
|