2022-09-02 09:54:40 +02:00
import { SlashCommandBuilder , EmbedBuilder , AttachmentBuilder , PermissionsBitField } 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' ) ) {
2022-09-02 09:54:40 +02:00
if ( interaction . isMessage ) {
type = ` -- ${ cmd . name } ` ;
}
else {
type = 'True/False' ;
}
2022-08-30 22:57:48 +02:00
}
else if ( constructorName . includes ( 'mentionable' ) ) {
type = 'User' ;
}
else if ( constructorName . includes ( 'attachment' ) ) {
type = 'Attachment' ;
}
return ` [ ${ cmd . name } : ${ type } ] ` ;
} ) ;
2022-09-02 09:54:40 +02:00
let p = '/' ;
if ( interaction . isMessage ) {
p = prefixs [ 0 ] ;
}
2022-08-30 22:57:48 +02:00
const embed = new EmbedBuilder ( )
2022-09-08 16:56:15 +02:00
. setColor ( interaction . member ? interaction . member . displayHexColor : 'Navy' )
2022-09-02 09:54:40 +02:00
. setTitle ( ` \` ${ p } ${ command . data . name } ${ usage . join ( ' ' ) } \` ` )
2022-08-30 22:57:48 +02:00
. 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 } ) ;
}
2022-09-02 09:54:40 +02:00
else {
const example = command . data . options . map ( cmd => {
let string = '"lorem ipsum"' ;
const constructorName = cmd . constructor . name . toLowerCase ( ) ;
if ( constructorName . includes ( 'boolean' ) ) {
if ( interaction . isMessage ) {
string = ` -- ${ cmd . name } ` ;
}
else {
string = 'True/False' ;
}
}
else if ( constructorName . includes ( 'mentionable' ) ) {
string = ` @ ${ interaction . user . username } ` ;
}
else if ( constructorName . includes ( 'attachment' ) ) {
string = 'Attachment' ;
}
if ( ! interaction . isMessage ) {
string = ` \` \` ${ cmd . name } : ${ string } \` \` ` ;
}
return string ;
} ) ;
embed . addFields ( { name : 'Example' , value : ` ${ p } ${ command . data . name } ${ example . join ( ' ' ) } ` , inline : true } ) ;
}
2022-08-30 22:57:48 +02:00
if ( command . alias ) {
2022-08-30 23:30:08 +02:00
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-09-02 09:54:40 +02:00
const perm = [ ] ;
command . userPermissions . forEach ( permission => {
perm . push ( new PermissionsBitField ( permission ) . toArray ( ) ) ;
} ) ;
embed . addFields ( { name : 'User permission' , value : ` \` ${ perm . join ( '` `' ) } \` ` , inline : true } ) ;
2022-08-30 22:57:48 +02:00
}
if ( command . clientPermissions ) {
2022-09-02 09:54:40 +02:00
const perm = [ ] ;
command . clientPermissions . forEach ( permission => {
perm . push ( new PermissionsBitField ( permission ) . toArray ( ) ) ;
} ) ;
embed . addFields ( { name : 'Bot permission' , value : ` \` ${ perm . 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 ( )
2022-09-08 16:56:15 +02:00
. setColor ( interaction . member ? interaction . member . displayHexColor : 'Navy' )
2022-08-30 22:57:48 +02:00
. 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 ) {
2022-09-02 10:00:10 +02:00
const title = {
fun : '🎉\u2000Fun' ,
utility : '🔩\u2000Utility' ,
admin : '⚡\u2000Admin' ,
owner : '🛠️\u2000Owner' ,
2022-09-23 19:41:07 +02:00
voice : '🗣️\u2000Voice' ,
2022-09-02 10:00:10 +02:00
} [ category ] ;
2022-08-30 22:57:48 +02:00
embed . addFields ( { name : title , value : ` \` ${ object [ category ] . join ( '` `' ) } \` ` } ) ;
}
return interaction . reply ( { embeds : [ embed ] } ) ;
}
} ,
} ;