2024-06-23 18:00:59 +05:00
|
|
|
const BaseEvent = require("../../base/BaseEvent");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
class GuildMemberAdd extends BaseEvent {
|
|
|
|
constructor() {
|
|
|
|
super({
|
|
|
|
name: "guildMemberAdd",
|
2022-12-15 21:02:38 +05:00
|
|
|
once: false,
|
2022-07-23 17:14:42 +05:00
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
}
|
|
|
|
|
2022-07-23 17:14:42 +05:00
|
|
|
/**
|
|
|
|
*
|
2023-11-05 16:03:23 +05:00
|
|
|
* @param {import("../../base/Client")} client
|
2022-07-23 17:14:42 +05:00
|
|
|
* @param {import("discord.js").GuildMember} member
|
|
|
|
*/
|
2022-08-02 17:18:47 +05:00
|
|
|
async execute(client, member) {
|
2022-01-04 02:18:28 +05:00
|
|
|
await member.guild.members.fetch();
|
|
|
|
|
2024-05-24 23:11:03 +05:00
|
|
|
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
|
|
|
}
|
2022-07-23 17:14:42 +05:00
|
|
|
}
|
|
|
|
|
2023-07-05 00:58:06 +05:00
|
|
|
module.exports = GuildMemberAdd;
|