JaBa/events/Guild/guildMemberAdd.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

const BaseEvent = require("../../base/BaseEvent");
2022-01-04 02:18:28 +05:00
class GuildMemberAdd extends BaseEvent {
constructor() {
super({
name: "guildMemberAdd",
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
2024-10-03 11:07:02 +05:00
if (guildData.plugins.autorole.enabled) {
const role = guildData.plugins.autorole.role;
if (role) {
await member.roles.add(role).catch(err => {
client.logger.error(`Failed to add role to ${member.user.tag}: ${err}`);
});
}
}
2022-01-04 02:18:28 +05:00
if (guildData.plugins.welcome.enabled) {
const channel = member.guild.channels.cache.get(guildData.plugins.welcome.channel);
2023-06-26 17:25:17 +05:00
2022-01-04 02:18:28 +05:00
if (channel) {
const message = guildData.plugins.welcome.message
.replace(/{user}/g, member)
.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 welcome message in channel ${channel.id}: ${err}`);
});
} else {
client.logger.warn(`Welcome channel not found: ${guildData.plugins.welcome.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 = GuildMemberAdd;