Skip to content
Snippets Groups Projects
Commit c86e4083 authored by Reviath's avatar Reviath
Browse files

Added guild member remove event.

parent 17d9fe1c
No related branches found
No related tags found
No related merge requests found
module.exports = {
guildmemberremove: (client, connection) => {
client.on('guildMemberRemove', async (member) => {
let channel_db;
let message_db;
await connection.query(`SELECT message FROM leave_message WHERE guild ='${member.guild.id}'`, function (err, result) {
if (err){
throw err;
};
if (result.length < 1) {
message_db = `<@${member.id}> left the server.`;
} else {
message_db = result[0].message;
};
});
await connection.query(`SELECT channel FROM leave_channel WHERE guild ='${member.guild.id}'`, function (err, result) {
if (err){
throw err;
};
if (result.length < 1) {
return;
} else {
channel_db = result[0].channel;
const channel = member.guild.channels.cache.get(channel_db);
if (!channel) {
return;
};
channel.send(message_db ? message_db.replace('{mention}', `${member}`).replace('{username}', `${member.user.username}`) : ``).catch(e => {
return;
});
}
});
});
}
};
...@@ -5,6 +5,7 @@ const dbconfig = require('./dbconfig.json'); ...@@ -5,6 +5,7 @@ const dbconfig = require('./dbconfig.json');
const ready = require('./events/ready'); const ready = require('./events/ready');
const message = require('./events/message'); const message = require('./events/message');
const memberadd = require('./events/memberadd'); const memberadd = require('./events/memberadd');
const memberremove = require('./events/memberremove');
const fs = require('fs'); const fs = require('fs');
const mysql = require('mysql'); const mysql = require('mysql');
...@@ -27,6 +28,7 @@ client.aliases = new Discord.Collection(); ...@@ -27,6 +28,7 @@ client.aliases = new Discord.Collection();
ready.ready(client); ready.ready(client);
message.message(client, config, Discord, connection); message.message(client, config, Discord, connection);
memberadd.guildmemberadd(client, connection); memberadd.guildmemberadd(client, connection);
memberremove.guildmemberremove(client, connection);
fs.readdir("./commands/", (err, files) => { fs.readdir("./commands/", (err, files) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment