Possible API change broke urban node module
comicallybad opened this issue · comments
ComicallyBad commented
This command has been working forever with no issues, today though I got an error, as I have not changed my code, and it's an error within the node module, I think the API must have changed.
My Code:
const { del } = require("../../functions.js");
const urban = require("urban");
const { MessageEmbed } = require("discord.js");
const { stripIndents } = require("common-tags");
module.exports = {
name: "urban",
aliases: ["urb", "urbandictionary", "ud"],
category: "fun",
description: "Gets an urban dictionary definition",
usage: "[search <term> | random]",
permissions: "member",
run: (client, message, args) => {
if (!args[0] || !["search", "random"].includes(args[0]))
return message.reply("Please provide <search|random> (query).").then(m => del(m, 7500));
let search = args[1] ? urban(args.slice(1).join(" ")) : urban.random();
try {
search.first(res => {
if (!res) return message.reply("No results found for this topic, sorry!").then(m => del(m, 7500));
let { word, definition, example, thumbs_up, thumbs_down, permalink, author } = res;
let description = stripIndents`**Defintion:** ${definition || "No definition"}
**Example:** ${example || "No Example"}
**Upvote:** ${thumbs_up || 0}
**Downvote:** ${thumbs_down || 0}
**Link:** [link to ${word}](${permalink || "https://www.urbandictionary.com/"})`
if (description.length >= 1024)
return message.reply("This definition is too long of a string for a message embed sorry!").then(m => del(m, 7500));
else {
let embed = new MessageEmbed()
.setColor("#0efefe")
.setAuthor(`Urban Dictionary | ${word}`, image)
.setDescription(description)
.setTimestamp()
.setFooter(`Written by ${author || "unknown"}`);
message.channel.send(embed)
}
});
} catch (err) {
return message.channel.send(`Error while searching... ${err}`).then(m => del(m, 7500));
}
}
}
Error Caught by my process.on(uncaughtExcemption) event not the catch statement:
10-05-2021 12-18-44 A new uncaughtExcemption error: SyntaxError: Unexpected end of JSON input
at JSON.parse (<anonymous>)
at IncomingMessage.<anonymous> (C:\Users\amp56\Documents\Projects\Comicallybot2.0\node_modules\urban\lib\urban.js:83:24)
at IncomingMessage.emit (events.js:412:35)
at endReadableNT (internal/streams/readable.js:1317:12)
at processTicksAndRejections (internal/process/task_queues.js:82:21) at: uncaughtException
ComicallyBad commented
Seems to be fixed now, didn't change anything but it is working again as normal.