2024-02-09 09:53:30 +00:00
const { PermissionFlagsBits } = require ( "discord.js" ) ;
2019-10-31 18:29:26 +00:00
module . exports = {
name : 'setdj' ,
2024-02-09 09:53:30 +00:00
async execute ( message , args , client , prefix ) {
2019-10-31 18:29:26 +00:00
if ( ! client . global . db . guilds [ message . guild . id ] . dj ) {
if ( ! client . global . db . guilds [ message . guild . id ] . permissions ) {
client . global . db . guilds [ message . guild . id ] . permissions = true ;
}
2024-02-09 09:53:30 +00:00
if ( message . guild . roles . cache . find ( x => x . name === "DJ" ) ) {
client . global . db . guilds [ message . guild . id ] . djrole = message . guild . roles . cache . find ( x => x . name === "DJ" ) . id ;
2019-10-31 18:29:26 +00:00
message . channel . send ( ':white_check_mark: I found a `DJ` role from this guild! This role is now the DJ role.' ) ;
2019-11-03 11:55:04 +00:00
client . global . db . guilds [ message . guild . id ] . dj = true ;
2019-10-31 18:29:26 +00:00
} else {
const permissions = message . channel . permissionsFor ( message . client . user ) ;
2024-02-09 09:53:30 +00:00
if ( ! permissions . has ( PermissionFlagsBits . ManageRoles ) ) return message . channel . send ( ':x: I cannot create roles (Manage roles), make sure I have the proper permissions! I will need this permission to create a `DJ` role since i did not find one!' ) ;
message . guild . createRole ( { name : 'DJ' } )
2019-10-31 18:29:26 +00:00
. then ( role => client . global . db . guilds [ message . guild . id ] . djrole = role . id )
. catch ( console . error )
2019-11-03 11:55:04 +00:00
client . global . db . guilds [ message . guild . id ] . dj = true ;
2019-10-31 18:29:26 +00:00
message . channel . send ( ':white_check_mark: I did not find a role `DJ` so i have created one for you!' ) ;
}
} else {
client . global . db . guilds [ message . guild . id ] . dj = false ;
message . channel . send ( ':white_check_mark: `DJ` now set to `false`' ) ;
}
}
2024-02-09 09:53:30 +00:00
} ;