TravBot-v3/src/commands/fun/urban.ts

32 lines
1.6 KiB
TypeScript
Raw Normal View History

import {Command, NamedCommand, RestCommand} from "../../core";
import {MessageEmbed} from "discord.js";
2021-04-08 11:37:49 +00:00
import urban from "relevant-urban";
export default new NamedCommand({
description: "Gives you a definition of the inputted word.",
2021-04-08 11:37:49 +00:00
run: "Please input a word.",
any: new RestCommand({
async run({send, message, channel, guild, author, member, client, args, combined}) {
2021-04-08 11:37:49 +00:00
// [Bug Fix]: Use encodeURIComponent() when emojis are used: "TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters"
urban(encodeURIComponent(combined))
2021-04-08 11:37:49 +00:00
.then((res) => {
const embed = new MessageEmbed()
.setColor(0x1d2439)
.setTitle(res.word)
.setURL(res.urbanURL)
.setDescription(`**Definition:**\n*${res.definition}*\n\n**Example:**\n*${res.example}*`)
// [Bug Fix] When an embed field is empty (if the author field is missing, like the top entry for "british"): "RangeError [EMBED_FIELD_VALUE]: MessageEmbed field values may not be empty."
.addField("Author", res.author || "N/A", true)
.addField("Rating", `**\`Upvotes: ${res.thumbsUp} | Downvotes: ${res.thumbsDown}\`**`);
if (res.tags && res.tags.length > 0 && res.tags.join(" ").length < 1024)
embed.addField("Tags", res.tags.join(", "), true);
2021-04-10 13:34:55 +00:00
send(embed);
2021-04-08 11:37:49 +00:00
})
.catch(() => {
2021-04-10 13:34:55 +00:00
send("Sorry, that word was not found.");
2021-04-08 11:37:49 +00:00
});
}
2021-04-08 11:37:49 +00:00
})
});