Bot-2.0/events/removeMember.js

42 lines
1.4 KiB
JavaScript
Raw Normal View History

2024-06-15 17:58:52 +00:00
const { Events, EmbedBuilder } = require('discord.js');
2024-06-16 08:28:17 +00:00
const fs = require('fs');
2024-06-15 17:58:52 +00:00
module.exports = {
2024-06-16 08:28:17 +00:00
name: Events.GuildMemberRemove,
2024-06-15 17:58:52 +00:00
once: false,
2024-06-16 08:28:17 +00:00
execute(member) {
const { guild, user } = member;
const filePath = `./guilds/guilds-${guild.id}.json`;
if (fs.existsSync(filePath)) {
const data = JSON.parse(fs.readFileSync(filePath));
if (!data.goodbye || !data.goodbyeChannel) return;
let title = data.goodbyeMessage.title;
let description = data.goodbyeMessage.content ? data.goodbyeMessage.content.replace("{{USER}}", user.username) : `Goodbye ${user.username}!`;
const embed = new EmbedBuilder()
.setTitle(title)
.setDescription(description)
.setColor("#ff0000")
.setThumbnail(user.avatarURL())
.setTimestamp();
guild.channels.fetch(data.goodbyeChannel)
.then(channel => {
if (channel) {
channel.send({ embeds: [embed] })
.catch(console.error);
} else {
console.error("Goodbye channel not found.");
}
})
.catch(console.error);
}
else
{
return;
}
2024-06-15 17:58:52 +00:00
}
};