-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathInviteTrack.js
More file actions
105 lines (68 loc) · 2.02 KB
/
InviteTrack.js
File metadata and controls
105 lines (68 loc) · 2.02 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Code By Amir! <3
const Discord = require('discord.js');
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_INVITES,
]
});
// Config
let LogChannelID = "ID";
let wlcMessage = "{member}, {tag}, {inviter}, {uses}, {code}"
//{member}, {tag}, {inviter}, {uses}, {code};
//;
client.once('ready', () => {
//create Collection
const gInvites = new Discord.Collection();
client.invites = gInvites;
console.log(`${client.user.tag} is online!`);
//get All bot guilds
for (let guild of client.guilds.cache.values()) {
//https://discord.gg/mQyRTdN9 << JOIN <<<
//fetch for guild invites
guild.invites.fetch().then(invite => {
// set Guild Invites
client.invites.set(guild.id, invite);
}).catch(error => {
console.log(error);
})
}
})
// on InviteCreate Event;
client.on('inviteCreate', async (invite) => {
// add new invites to guild collection;
client.invites.set(invite.guild.id, await invite.guild.invites.fetch());
});
//on Member Add Event;
client.on('guildMemberAdd', async (member) => {
let guild = member.guild;
if (member.user.bot) return;
//get Cached invites for member guild;
const cInvites = client.invites.get(guild.id);
//get new Invites;
let nInvites = await guild.invites.fetch();
//get the invite code;
const theInvite = await nInvites.find(invite =>{
return cInvites.get(invite.code).uses == invite.uses;
});
//set new Invites;
await client.invites.set(guild.id, nInvites);
//invite Info
const {code, uses, inviter} = theInvite;
//get Log Channel;
let serverLog = guild.channels.cache.get(LogChannelID);
//if log ex!
if(serverLog){
serverLog.send({content: wlcMessage
.replace(/{member}/, `${member}`)
.replace(/{tag}/, `${member.user.tag}`)
.replace(/{code}/, `${code}`)
.replace(/{inviter}/, `${inviter}`)
.replace(/{uses}/, `${uses}`)
})
}
});
client.login('TOKEN');
// Code By Amir! <3