2022-01-16 17:37:07 +00:00
import { SlashCommandBuilder } from "@discordjs/builders" ;
2021-04-13 12:38:52 +00:00
import { NamedCommand , RestCommand } from "onion-lasers" ;
2022-01-16 17:37:07 +00:00
import { MessageEmbed , CommandInteraction } from "discord.js" ;
2021-04-08 11:37:49 +00:00
import urban from "relevant-urban" ;
2021-03-31 01:40:29 +00:00
2022-01-16 17:37:07 +00:00
export const header = new SlashCommandBuilder ( )
. setDescription ( "Gives you a definition of the inputted word." )
. addStringOption ( ( option ) = >
option . setName ( "word" ) . setDescription ( "The word you're looking for" ) . setRequired ( true )
) ;
export async function handler ( interaction : CommandInteraction ) {
const { options } = interaction ;
await interaction . reply ( "Working on it...." ) ;
const response = options . getString ( "word" , true ) ;
// [Bug Fix]: Use encodeURIComponent() when emojis are used: "TypeError [ERR_UNESCAPED_CHARACTERS]: Request path contains unescaped characters"
urban ( encodeURIComponent ( response ) )
. then ( async ( 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 ) ;
interaction . editReply ( "Here you go!" ) ;
await interaction . editReply ( { embeds : [ embed ] } ) ;
} )
. catch ( async ( ) = > {
await interaction . editReply ( "Sorry, that word was not found." ) ;
} ) ;
}
2021-04-05 12:21:27 +00:00
export default new NamedCommand ( {
2021-03-31 01:40:29 +00:00
description : "Gives you a definition of the inputted word." ,
2021-04-08 11:37:49 +00:00
run : "Please input a word." ,
2021-04-10 17:07:55 +00:00
any : new RestCommand ( {
2021-04-11 09:11:21 +00:00
async run ( { send , 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"
2021-04-10 17:07:55 +00:00
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-10-29 12:52:46 +00:00
send ( { embeds : [ 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-03-31 01:40:29 +00:00
}
2021-04-08 11:37:49 +00:00
} )
2021-03-31 01:40:29 +00:00
} ) ;