-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
guildMemberAdd.js
52 lines (46 loc) · 1.66 KB
/
guildMemberAdd.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const { Events, EmbedBuilder, ChannelType } = require('discord.js');
const fs = require('fs');
const path = require('path');
module.exports = {
name: Events.GuildMemberAdd,
once: false,
async execute(member) {
try {
const { user, guild } = member;
const joinLeavesDir = './config/joinleave';
const guildConfigFile = path.join(joinLeavesDir, `${guild.id}.json`);
if (fs.existsSync(guildConfigFile)) {
const configFileData = fs.readFileSync(guildConfigFile, 'utf-8');
const guildConfig = JSON.parse(configFileData);
const channelId = guildConfig.joinLeaveChannel;
if (channelId) {
const channel = guild.channels.cache.get(channelId);
if (channel && channel.type === ChannelType.GuildText) {
const embed = new EmbedBuilder()
.setTitle(`${user.username} joined the server`)
.setColor('#00FF00')
.setURL(`https://discord.com/users/${user.id}`)
.setThumbnail(user.displayAvatarURL())
.addFields(
{ name: 'User ID', value: user.id, inline: true },
{ name: 'User Tag', value: user.tag, inline: true },
{ name: 'Avatar URL', value: user.displayAvatarURL({ dynamic: true }) },
{ name: 'Joined Discord', value: user.createdAt.toDateString(), inline: true },
{ name: 'Joined Server', value: member.joinedAt.toDateString(), inline: true },
);
await channel.send({ embeds: [embed] });
}
else {
console.log('The specified join/leave channel is not a text channel.');
}
}
else {
console.log('No join/leave channel specified in the config file.');
}
}
}
catch (error) {
console.error('There was an error:', error);
}
},
};