2021-09-17 18:28:39 +02:00
const Discord = require ( "discord.js" ) ;
2021-06-12 12:53:51 +02:00
const { readdirSync } = require ( "fs" ) ;
module . exports = {
name : "help" ,
aliases : [ "h" ] ,
usage : "(Command/Category)" ,
description : "Shows all available bot commands" ,
category : "Utilities" ,
run : async ( client , message , args ) => {
const p = await client . prefix ( message ) ;
const emoji = {
2021-06-24 09:53:19 +02:00
CODM : "<a:AA99_codm_logo:840231960441257995>" ,
Config : "<:staff:840231971526803467>" ,
2021-06-12 12:53:51 +02:00
Economy : client . currency ,
Fun : "<a:lollll:804325253265621012>" ,
2021-09-17 18:28:39 +02:00
Moderation : "🔨" ,
Utilities : "⚙" ,
2021-06-24 09:53:19 +02:00
Music : "<a:music:840231980692144130>" ,
2021-06-12 12:53:51 +02:00
Giveaway : "<a:DankCat:798963811902160896>" ,
2021-09-17 18:28:39 +02:00
Information : "ℹ " ,
2021-06-12 12:53:51 +02:00
} ;
if ( ! args [ 0 ] ) {
2021-09-17 18:28:39 +02:00
const directories = [
... new Set ( client . commands . map ( cmd => cmd . directory ) ) ,
] ;
const categories = directories . map ( dir => {
if ( dir == "Owner" ) return ;
const getCmds = client . commands
. filter ( c => c . directory == dir )
. map ( cmd => {
return {
name : cmd . name || "No command name" ,
} ;
} ) ;
return {
directory : dir ,
commands : getCmds ,
2021-06-12 12:53:51 +02:00
} ;
} ) ;
2021-09-17 18:28:39 +02:00
const embed = new Discord . MessageEmbed ( )
2021-06-24 09:53:19 +02:00
. setTitle ( ` ** ${ client . user . username } commands** ` )
2021-09-17 18:28:39 +02:00
. setDescription ( ` Please choose a category in the dropdown menu ` )
. setColor ( client . color )
. setTimestamp ( )
. setAuthor (
` Requested by ${ message . author . tag } ` ,
message . author . displayAvatarURL ( { dynamic : true } )
)
2021-06-24 09:53:19 +02:00
. addField (
"**Invite Link**" ,
` **Invite me to your server by clicking [here](https://discord.com/api/oauth2/authorize?client_id= ${ client . user . id } &permissions=4231314550&scope=bot%20applications.commands)** `
)
. addField (
"**Support Server Invite**" ,
"**Join the support server by clicking [here](https://discord.gg/SbQHChmGcp)**"
)
. addField (
"**Premium**" ,
2021-09-06 12:38:25 +02:00
"**You can either boost support server or subscribe to developer's team [Ko-fi](https://ko-fi.com/cathteam) or gift a nitro to one of the developer team **"
2021-06-24 09:53:19 +02:00
)
2021-06-12 12:53:51 +02:00
. setURL ( client . web )
. setFooter (
` Requested by ${ message . author . tag } ` ,
message . author . displayAvatarURL ( { dynamic : true } )
2021-09-17 18:28:39 +02:00
) ;
const components = state => [
new Discord . MessageActionRow ( ) . addComponents (
new Discord . MessageSelectMenu ( )
. setCustomId ( "help-menu" )
. setPlaceholder ( ` Please select a category ` )
. setDisabled ( state )
. addOptions (
categories . map ( cmd => {
return {
label : cmd . directory ,
value : cmd . directory ,
description : ` Commands from ${ cmd . directory } category ` ,
emoji : emoji [ cmd . directory ] || null ,
} ;
} )
)
) ,
] ;
const msg = await message . channel . send ( {
embeds : [ embed ] ,
components : components ( false ) ,
2021-06-12 12:53:51 +02:00
} ) ;
2021-09-17 18:28:39 +02:00
const filter = m => m . user . id === message . author . id ;
const collector = message . channel . createMessageComponentCollector ( {
filter ,
componentType : "SELECT_MENU" ,
time : 60000 ,
2021-06-12 12:53:51 +02:00
} ) ;
2021-09-17 18:28:39 +02:00
collector . on ( "collect" , async interaction => {
const [ directory ] = interaction . values ;
const category = categories . find ( u => u . directory === directory ) ;
const newembed = new Discord . MessageEmbed ( )
2021-06-12 12:53:51 +02:00
. setTitle (
2021-09-17 18:28:39 +02:00
` ${ emoji [ directory ] } ${ directory } Commands ${ emoji [ directory ] } `
2021-06-12 12:53:51 +02:00
)
2021-09-17 18:28:39 +02:00
. setAuthor (
` Requested by ${ message . author . tag } ` ,
message . author . displayAvatarURL ( { dynamic : true } )
2021-06-12 12:53:51 +02:00
)
. setTimestamp ( )
. setURL ( client . web )
. setColor ( client . color )
2021-09-17 18:28:39 +02:00
. setFooter ( ` Please use /help (Command Name) for more details ` )
. setDescription (
category . commands
. map ( cmd => {
return [ ` \` ${ cmd . name } \` ` ] ;
} )
. join ( ", " )
) ;
interaction . reply ( { embeds : [ newembed ] } ) ;
2021-06-12 12:53:51 +02:00
} ) ;
2021-09-17 18:28:39 +02:00
collector . on ( "end" , ( ) => msg . edit ( { components : components ( true ) } ) ) ;
2021-06-12 12:53:51 +02:00
} else {
const command =
client . commands . get ( args [ 0 ] . toLowerCase ( ) ) ||
client . commands . find (
c => c . aliases && c . aliases . includes ( args [ 0 ] . toLowerCase ( ) )
) ;
if ( ! command ) {
2021-09-17 18:28:39 +02:00
message . channel . send ( {
content : ` There isn't any command named " ${ args [ 0 ] } " ` ,
} ) ;
2021-06-12 12:53:51 +02:00
} else {
2021-06-24 09:53:19 +02:00
if ( command . UserPerm && Array . isArray ( command . UserPerm ) ) {
UserPermissions = command . UserPerm ;
} else UserPermissions = [ command . UserPerm ? command . UserPerm : "" ] ;
if ( command . BotPerm && Array . isArray ( command . BotPerm ) ) {
BotPermissions = command . BotPerm ;
} else BotPermissions = [ command . BotPerm ? command . BotPerm : "" ] ;
const BotPerms = BotPermissions . map ( x =>
x
. split ( "_" )
. map ( y => y [ 0 ] + y . substring ( 1 , y . length ) . toLowerCase ( ) )
. join ( " " )
) . join ( ", " ) ;
const UserPerms = UserPermissions . map ( x =>
x
. split ( "_" )
. map ( y => y [ 0 ] + y . substring ( 1 , y . length ) . toLowerCase ( ) )
. join ( " " )
) . join ( ", " ) ;
2021-09-17 18:28:39 +02:00
const embed = new Discord . MessageEmbed ( )
2021-06-12 12:53:51 +02:00
. setTitle ( ` " ${ command . name } " command details ` )
. addField (
"**Command**:" ,
command . name ? ` \` ${ command . name } \` ` : "N/A"
2021-06-24 09:53:19 +02:00
) ;
if ( command . aliases ) {
embed . addField ( "**Aliases**:" , ` \` ${ command . aliases . join ( ", " ) } \` ` ) ;
}
if ( command . usage ) {
embed . addField (
2021-06-12 12:53:51 +02:00
"**Usage**:" ,
2021-06-24 09:53:19 +02:00
` \` ${ p } ${ command . name } ${ command . usage } \` `
) ;
} else {
embed . addField ( "**Usage**:" , ` \` ${ p } ${ command . name } \` ` ) ;
}
if ( command . description ) {
embed . addField ( "**Description**:" , command . description ) ;
}
if ( command . timeout ) {
2021-09-17 18:28:39 +02:00
embed . addField (
"**Cooldown**:" ,
utils . ms ( command . timeout , { long : true } )
) ;
2021-06-24 09:53:19 +02:00
}
if ( command . UserPerm ) {
embed . addField ( "**Required User Permission**:" , UserPerms ) ;
}
if ( command . BotPerm ) {
embed . addField ( "**Required Bot Permission**:" , BotPerms ) ;
}
embed
2021-06-12 12:53:51 +02:00
. setFooter (
` Requested by ${ message . author . tag } ` ,
message . author . displayAvatarURL ( { dynamic : true } )
)
. setTimestamp ( )
. setURL ( client . web )
. setColor ( client . color ) ;
2021-09-17 18:28:39 +02:00
message . reply ( { embeds : [ embed ] } ) ;
2021-06-12 12:53:51 +02:00
}
}
} ,
} ;