2022-08-31 23:03:10 +02:00
import { SlashCommandBuilder , EmbedBuilder , AttachmentBuilder } from 'discord.js' ;
2022-08-30 22:57:48 +02:00
import fs from 'node:fs' ;
const { ownerId , prefix } = process . env ;
const prefixs = prefix . split ( ',' ) ;
export default {
data : new SlashCommandBuilder ( )
. setName ( 'help' )
2022-09-01 01:43:59 +02:00
. setDescription ( 'Displays a list of commands or information about a command.' )
. addStringOption ( option =>
option . setName ( 'command' )
. setDescription ( 'The command you want more details about.' ) ) ,
2022-08-30 22:57:48 +02:00
category : 'utility' ,
async execute ( interaction , args , client ) {
2022-09-01 01:43:59 +02:00
if ( args . command ) {
const command = client . commands . get ( args . command ) ;
if ( ! command ) return interaction . reply ( ` Did not found any command named \` \` ${ args . command } \` \` . Please make sure it is a valid command and not an alias. ` ) ;
2022-08-30 22:57:48 +02:00
const description = Object . assign ( {
content : 'No description available.' ,
usage : '' ,
examples : [ ] ,
fields : [ ] ,
} , command . data ) ;
const usage = command . data . options . map ( cmd => {
let type = 'String' ;
const constructorName = cmd . constructor . name . toLowerCase ( ) ;
if ( constructorName . includes ( 'boolean' ) ) {
type = 'True/False' ;
}
else if ( constructorName . includes ( 'mentionable' ) ) {
type = 'User' ;
}
else if ( constructorName . includes ( 'attachment' ) ) {
type = 'Attachment' ;
}
return ` [ ${ cmd . name } : ${ type } ] ` ;
} ) ;
const embed = new EmbedBuilder ( )
. setColor ( interaction . member ? interaction . member . displayHexColor : 'NAVY' )
. setTitle ( ` \` ${ prefixs [ 0 ] } ${ command . data . name } ${ usage . join ( ' ' ) } \` ` )
. addFields (
{ name : 'Description' , value : description . description } ,
)
. setFooter ( { text : ` All the available prefix: ${ prefixs . join ( ' | ' ) } ` } ) ;
for ( const field of description . fields ) embed . addFields ( { name : field . name , value : field . value } ) ;
if ( description . examples . length ) {
const text = ` ${ prefixs [ 0 ] } ${ command . alias [ 0 ] } ` ;
embed . addFields ( { name : 'Examples' , value : ` \` ${ text } ${ description . examples . join ( ` \` \n \` ${ text } ` ) } \` ` , inline : true } ) ;
}
if ( command . alias ) {
2022-08-30 23:30:08 +02:00
console . log ( command . alias . length ) ;
if ( command . alias . length >= 1 ) {
embed . addFields ( { name : 'Aliases' , value : ` \` ${ command . alias . join ( '` `' ) } \` ` , inline : true } ) ;
2022-08-30 22:57:48 +02:00
}
}
if ( command . userPermissions ) {
2022-08-30 23:30:08 +02:00
embed . addFields ( { name : 'User permission' , value : ` \` ${ command . userPermissions . join ( '` `' ) } \` ` , inline : true } ) ;
2022-08-30 22:57:48 +02:00
}
if ( command . clientPermissions ) {
2022-08-30 23:30:08 +02:00
embed . addFields ( { name : 'Bot permission' , value : ` \` ${ command . clientPermissions . join ( '` `' ) } \` ` , inline : true } ) ;
2022-08-30 22:57:48 +02:00
}
if ( fs . existsSync ( ` ./asset/img/command/ ${ command . category } / ${ command . data . name } .png ` ) ) {
2022-08-31 23:03:10 +02:00
const file = new AttachmentBuilder ( ` ./asset/img/command/ ${ command . category } / ${ command . data . name } .png ` ) ;
2022-08-30 22:57:48 +02:00
embed . setImage ( ` attachment:// ${ command . data . name } .png ` ) ;
2022-08-31 23:03:10 +02:00
return interaction . reply ( { embeds : [ embed ] , files : [ file ] } ) ;
2022-08-30 22:57:48 +02:00
}
return interaction . reply ( { embeds : [ embed ] } ) ;
}
else {
const embed = new EmbedBuilder ( )
. setColor ( interaction . member ? interaction . member . displayHexColor : 'NAVY' )
. addFields ( { name : 'Command List' , value : ` This is a list of commands. \n To view details for a command, do \` ${ prefixs [ 0 ] } help <command> \` . ` } )
. setFooter ( { text : ` All the available prefix: ${ prefixs . join ( '| ' ) } ` } ) ;
const object = { } ;
for ( const command of client . commands . values ( ) ) {
2022-08-30 23:30:08 +02:00
if ( command . category === 'secret' ) continue ;
2022-09-02 08:32:51 +02:00
if ( interaction . user . id !== ownerId && command . category === 'owner' ) continue ;
2022-08-30 22:57:48 +02:00
if ( object [ command . category ] ) {
object [ command . category ] . push ( command . data . name ) ;
}
else {
object [ command . category ] = [ command . data . name ] ;
}
}
for ( const category in object ) {
let title ;
2022-09-02 08:32:51 +02:00
if ( interaction . user . id === ownerId ) {
2022-08-30 22:57:48 +02:00
title = {
fun : '🎉\u2000Fun' ,
utility : '🔩\u2000Utility' ,
admin : '⚡\u2000Admin' ,
owner : '🛠️\u2000Owner' ,
} [ category ] ;
}
else {
title = {
fun : '🎉\u2000Fun' ,
utility : '🔩\u2000Utility' ,
admin : '⚡\u2000Admin' ,
} [ category ] ;
}
2022-09-02 08:32:51 +02:00
console . log ( title ) ;
2022-08-30 22:57:48 +02:00
embed . addFields ( { name : title , value : ` \` ${ object [ category ] . join ( '` `' ) } \` ` } ) ;
}
return interaction . reply ( { embeds : [ embed ] } ) ;
}
} ,
} ;