@ -15,7 +15,7 @@ class char extends Command{
}
async run ( message , args )
{
if ( ! args [ 0 ] ) return new ErrorMessage ( this . client ) . send ( ErrorType . Arguments, message )
if ( ! args [ 0 ] ) return new ErrorMessage ( this . client ) . send ( ErrorType . No Arguments, message )
const data = await new Anilist ( ) . searchChar ( args . join ( ' ' ) ) ;
if ( data == 'Error' ) return new ErrorMessage ( this . client ) . send ( ErrorType . Arguments , message , [ ` Couldn't find any character with the search argument you provided. ` ] )
const embed = new EmbedBuilder ( ) ;
@ -51,18 +51,22 @@ class char extends Command{
// console.log(data.length, embeds.length, embeds)
const filter = i => i . customId . slice ( 0 , - 1 ) === randomID ;
await message . channel . send ( { ephemeral : true , embeds , components : [ row ] } ) ;
const sentMessage = await message . channel . send ( { ephemeral : true , embeds , components : [ row ] } ) ;
const collector = message . channel . createMessageComponentCollector ( { filter , time : 60000 } ) ;
collector . on ( 'collect' , async m =>
{
message . delete ( ) ;
m . message . delete ( ) ;
if ( m . customId [ m . customId . length - 1 ] != 4 ) sendMessage ( data [ m . customId [ m . customId . length - 1 ] ] . id );
if ( m . customId [ m . customId . length - 1 ] != 4 ) sendMessage ( data [ m . customId [ m . customId . length - 1 ] ] . id , this . client );
} ) ;
collector . on ( 'end' , async ( ) =>
{
this . client . guilds . cache . get ( sentMessage . guildId ) . channels . cache . get ( sentMessage . channelId ) . messages . cache . get ( sentMessage . id ) . edit ( { components : [ ] } ) ;
} )
/ * *
* @ param { Number } id
* /
async function sendMessage ( id )
async function sendMessage ( id , client )
{
const data = await new Anilist ( ) . getCharInfo ( id ) ;
data . description = data . description . replaceAll ( '~!' , '' ) . replaceAll ( '!~' , '' ) . replaceAll ( /<[^>]*>/g , '' ) ;
@ -80,18 +84,9 @@ class char extends Command{
. addFields (
{ name : 'Page' , value : data . url , inline : true }
) ;
if ( data . age )
{
embed . addFields ( { name : 'Age:' , value : data . age , inline : true } ) ;
}
if ( data . gender )
{
embed . addFields ( { name : 'Gender:' , value : data . gender ? data . gender : '' , inline : true } , ) ;
}
if ( ! data . name . native )
{
embed . setTitle ( ` ${ data . name . full } ` )
}
if ( data . age ) embed . addFields ( { name : 'Age:' , value : data . age , inline : true } ) ;
if ( data . gender ) embed . addFields ( { name : 'Gender:' , value : data . gender ? data . gender : '' , inline : true } , ) ;
if ( ! data . name . native ) embed . setTitle ( ` ${ data . name . full } ` )
const randomID = Random ( ) ;
const row = new ActionRowBuilder ( )
. addComponents (
@ -107,6 +102,10 @@ class char extends Command{
{
m . message . delete ( ) ;
} ) ;
collector . on ( 'end' , async ( ) =>
{
client . guilds . cache . get ( sentMessage . guildId ) . channels . cache . get ( sentMessage . channelId ) . messages . cache . get ( sentMessage . id ) . edit ( { components : [ ] } ) ;
} )
}
}