2019-05-10 16:36:17 +02:00
const { Command } = require ( 'discord-akairo' ) ;
const fs = require ( 'fs' ) ;
class byeCommand extends Command {
constructor ( ) {
super ( 'bye' , {
2019-11-09 12:02:55 +01:00
aliases : [ 'bye' , 'leave' ] ,
2019-05-10 16:36:17 +02:00
category : 'admin' ,
channelRestriction : 'guild' ,
userPermissions : [ 'MANAGE_CHANNELS' ] ,
2019-11-09 12:02:55 +01:00
clientPermissions : [ 'SEND_MESSAGES' ] ,
2019-05-10 16:36:17 +02:00
args : [
2019-11-09 12:02:55 +01:00
{
id : 'remove' ,
match : 'flag' ,
flag : '--remove'
} ,
2019-05-10 16:36:17 +02:00
{
id : 'message' ,
type : 'string' ,
2019-11-09 12:02:55 +01:00
match : 'rest' ,
default : '[member] just left the server :('
2019-05-10 16:36:17 +02:00
}
] ,
description : {
2019-05-11 18:34:19 +02:00
content : 'Send a message to the current channel when a person leave, you can use [member] to show the member username and [server] to show the name of the server' ,
2019-05-10 16:36:17 +02:00
usage : '[bye message]' ,
2019-11-09 12:02:55 +01:00
examples : [ '[member] left the server, he deserve a ban' ]
2019-05-10 16:36:17 +02:00
}
} ) ;
}
async exec ( message , args ) {
let byeChannel = message . channel . id ;
2019-11-09 12:02:55 +01:00
if ( args . remove ) {
fs . unlink ( ` ./welcome/ ${ message . guild . id } .json ` , ( err ) => {
if ( err ) {
console . error ( err ) ;
return message . channel . send ( 'An error has occured, there is most likely no welcome message set!' ) ;
} else {
return message . channel . send ( 'Disabled unwelcome message' ) ;
}
} ) ;
}
2019-05-10 16:36:17 +02:00
fs . writeFile ( ` ./bye/ ${ message . guild . id } .json ` , ` {"channel": " ${ byeChannel } ", "message": " ${ args . message } "} ` , function ( err ) {
if ( err ) {
console . log ( err ) ;
2019-11-09 12:02:55 +01:00
return message . channel . send ( 'An error has occured! im gonna be honest with you, i do not know what happened yet! but fear not! i will look into it!' ) ;
2019-05-10 16:36:17 +02:00
}
} ) ;
return message . channel . send ( ` This channel will now be used to send message when user leave with the following message: ${ args . message } ` ) ;
}
}
module . exports = byeCommand ;