JaBa/events/Guild/guildMemberRemove.js

41 lines
1.1 KiB
JavaScript
Raw Normal View History

const BaseEvent = require("../../base/BaseEvent");
2022-01-04 02:18:28 +05:00
class GuildMemberRemove extends BaseEvent {
constructor() {
super({
name: "guildMemberRemove",
once: false,
});
2022-01-04 02:18:28 +05:00
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").GuildMember} member
*/
async execute(client, member) {
2022-01-04 02:18:28 +05:00
await member.guild.members.fetch();
const guildData = await client.getGuildData(member.guild.id);
2022-01-04 02:18:28 +05:00
if (guildData.plugins.goodbye.enabled) {
const channel = member.guild.channels.cache.get(guildData.plugins.goodbye.channel);
2023-06-26 17:25:17 +05:00
2022-01-04 02:18:28 +05:00
if (channel) {
const message = guildData.plugins.goodbye.message
.replace(/{user}/g, member.user.getUsername())
2022-01-04 02:18:28 +05:00
.replace(/{server}/g, member.guild.name)
2022-08-08 18:19:56 +05:00
.replace(/{membercount}/g, member.guild.memberCount);
2023-06-26 17:25:17 +05:00
2024-10-03 11:07:02 +05:00
await channel.send({ content: message }).catch(err => {
client.logger.error(`Failed to send goodbye message in channel ${channel.id}: ${err}`);
});
} else {
client.logger.warn(`Goodbye channel not found: ${guildData.plugins.goodbye.channel}`);
2022-01-13 00:26:23 +05:00
}
}
2022-01-04 02:18:28 +05:00
}
}
2023-07-05 00:58:06 +05:00
module.exports = GuildMemberRemove;